Skip to content

Commit

Permalink
Persisting owner operated answer, adding optional label (#817)
Browse files Browse the repository at this point in the history
* Persisting owner operated answer, adding optional label

* Role selection optional ? added

* adding docker compose for BETA
  • Loading branch information
kikemarquez8 authored Apr 27, 2021
1 parent 277d09d commit 707761c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 10 deletions.
53 changes: 53 additions & 0 deletions docker-compose.beta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: "3.7"

volumes:
postgres-data:
driver: local

services:
db:
container_name: litefarm-db
image: postgres:13
ports:
- "5433:5432"
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_DB: ${POSTGRES_DB}
healthcheck:
test: [ "CMD", "pg_isready", "-U", "postgres" ]
interval: 5s
timeout: 5s
retries: 5
volumes:
- ~/docker/volumes/postgres:/var/lib/postgresql/data
backend:
container_name: litefarm-api
deploy:
restart_policy:
condition: on-failure
max_attempts: 3
build:
context: ./packages/api
dockerfile: prod.Dockerfile
volumes:
- /etc/letsencrypt:/usr/src/letsencrypt
ports:
- "5000:5000"
environment:
WAIT_HOSTS: litefarm-db:5432
NODE_ENV: integration
DEV_DATABASE_HOST: ${DEV_DATABASE_HOST}
DEV_DATABASE: ${DEV_DATABASE}
DEV_DATABASE_USER: ${DEV_DATABASE_USER}
DEV_DATABASE_PASSWORD: ${DEV_DATABASE_PASSWORD}
frontend:
container_name: litefarm-web
build:
context: ./packages/webapp
dockerfile: prod.Dockerfile
volumes:
- /etc/letsencrypt:/etc/letsencrypt
ports:
- "80:80"
- "443:443"
2 changes: 1 addition & 1 deletion packages/webapp/src/components/RoleSelection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function PureRoleSelection({
<Radio classes={inputClasses} {...inputs[0]} />
<Radio classes={inputClasses} {...inputs[1]} />
<Radio classes={inputClasses} {...inputs[2]} />
<Title>{t('ROLE_SELECTION.IS_OWNER_OPERATED')}</Title>
<Title>{t('ROLE_SELECTION.IS_OWNER_OPERATED')} <Label sm>{t('common:OPTIONAL')}</Label></Title>
<Radio classes={inputClasses} {...inputs[3]} />
<Radio classes={inputClasses} {...inputs[4]} />
</Form>
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/containers/AddFarm/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ export function* patchRoleSaga({ payload }) {
call(axios.patch, patchRoleUrl(farm_id, user_id), { role_id }, header),
!step_two && call(axios.patch, patchStepUrl(farm_id, user_id), step, header),
]);
yield put(patchRoleStepTwoSuccess({ ...step, user_id, farm_id, role_id }));
if(owner_operated !== null) {
yield call(axios.patch, patchFarmUrl(farm_id), { owner_operated }, header);
}
yield put(patchRoleStepTwoSuccess({ ...step, user_id, farm_id, role, role_id, owner_operated }));
callback && callback();
} catch (e) {
console.log('fail to update role');
Expand Down
23 changes: 16 additions & 7 deletions packages/webapp/src/containers/RoleSelection/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { useForm } from 'react-hook-form';
import React from 'react';
import React, { useEffect } from 'react';
import PureRoleSelection from '../../components/RoleSelection';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { patchRole } from '../AddFarm/saga';
import history from '../../history';
import { roleToId } from './roleMap';
import { useTranslation } from 'react-i18next';
import { userFarmSelector } from "../userFarmSlice";

function RoleSelection() {
const { t } = useTranslation();
const { register, handleSubmit } = useForm();
const { register, handleSubmit, setValue } = useForm();
const ROLE = 'role';
const OWNER_OPERATED = 'owner_operated_string';
const OWNER_OPERATED = 'owner_operated';
const { role, owner_operated } = useSelector(userFarmSelector);
const dispatch = useDispatch();
const onSubmit = ({ role, owner_operated_string}) => {

const onSubmit = ({ role, owner_operated }) => {
const callback = () => history.push('/consent');
const owner_operated = owner_operated_string === "true" ? true : owner_operated_string === "false" ? false : null;
dispatch(patchRole({ role, owner_operated, role_id: roleToId[role], callback }));
const boolOwnerOperated = owner_operated === "true" ? true : owner_operated === "false" ? false : null;
dispatch(patchRole({ role, owner_operated: boolOwnerOperated, role_id: roleToId[role], callback }));
};

useEffect(() => {
setValue(ROLE, role);
setValue(OWNER_OPERATED, owner_operated?.toString());
}, [])

const onGoBack = () => {
history.push('/add_farm');
};
Expand Down
4 changes: 3 additions & 1 deletion packages/webapp/src/containers/userFarmSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ const userFarmSlice = createSlice({
},
postFarmSuccess: addUserFarm,
patchRoleStepTwoSuccess: (state, { payload }) => {
const { step_two, step_two_end, role_id, farm_id, user_id } = payload;
const { step_two, step_two_end, role_id, farm_id, user_id, owner_operated, role } = payload;
Object.assign(state.byFarmIdUserId[farm_id][user_id], {
step_two,
step_two_end,
role_id,
role,
owner_operated
});
},
patchConsentStepThreeSuccess: (state, { payload }) => {
Expand Down

0 comments on commit 707761c

Please sign in to comment.