From 216ba6dc93b81de754c5a08aceaed1762bf03566 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Fri, 19 Jan 2024 12:48:53 -0800 Subject: [PATCH 1/6] Merge pull request #3086 from LiteFarmOrg/LF-4023-Finances-menu-item-not-highlighted LF-4023 fix finances menu item not highlighted --- .../src/components/Finances/FinancesCarrousel/index.jsx | 3 ++- packages/webapp/src/hooks/useGetMenuItems.jsx | 6 ++++-- packages/webapp/src/routes/FinancesRoutes.jsx | 3 ++- packages/webapp/src/util/siteMapConstants.ts | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/webapp/src/components/Finances/FinancesCarrousel/index.jsx b/packages/webapp/src/components/Finances/FinancesCarrousel/index.jsx index 9e7146b1e7..3038ffba8c 100644 --- a/packages/webapp/src/components/Finances/FinancesCarrousel/index.jsx +++ b/packages/webapp/src/components/Finances/FinancesCarrousel/index.jsx @@ -30,6 +30,7 @@ import { Semibold, Text } from '../../Typography'; import clsx from 'clsx'; import TextButton from '../../Form/Button/TextButton'; import { + ACTUAL_REVENUE_URL, ESTIMATED_REVENUE_URL, LABOUR_URL, OTHER_EXPENSE_URL, @@ -84,7 +85,7 @@ const FinancesCarrousel = ({
history.push('/finances/actual_revenue')} + onClick={() => history.push(ACTUAL_REVENUE_URL)} > {t('SALE.FINANCES.TOTAL_REVENUE')} diff --git a/packages/webapp/src/hooks/useGetMenuItems.jsx b/packages/webapp/src/hooks/useGetMenuItems.jsx index 4d7bf92ffa..924612cd64 100644 --- a/packages/webapp/src/hooks/useGetMenuItems.jsx +++ b/packages/webapp/src/hooks/useGetMenuItems.jsx @@ -28,8 +28,10 @@ import { useSelector } from 'react-redux'; import { isAdminSelector } from '../containers/userFarmSlice'; import styles from '../components/Navigation/SideMenu/styles.module.scss'; import { + ACTUAL_REVENUE_URL, ESTIMATED_REVENUE_URL, FINANCES_HOME_URL, + FINANCES_URL, LABOUR_URL, OTHER_EXPENSE_URL, } from '../util/siteMapConstants'; @@ -55,7 +57,7 @@ export const useGetMenuItems = () => { list.splice(3, 0, { label: t('MENU.FINANCES'), icon: , - path: FINANCES_HOME_URL, + path: FINANCES_URL, key: 'finances', subMenu: [ { @@ -71,7 +73,7 @@ export const useGetMenuItems = () => { { label: t('MENU.LABOUR_EXPENSES'), path: LABOUR_URL, key: 'labour' }, { label: t('MENU.ACTUAL_REVENUES'), - path: '/finances/actual_revenue', + path: ACTUAL_REVENUE_URL, key: 'actual_revenue', }, { diff --git a/packages/webapp/src/routes/FinancesRoutes.jsx b/packages/webapp/src/routes/FinancesRoutes.jsx index a3cfefffc8..19a294bc8d 100644 --- a/packages/webapp/src/routes/FinancesRoutes.jsx +++ b/packages/webapp/src/routes/FinancesRoutes.jsx @@ -16,6 +16,7 @@ import React from 'react'; import { Route, Switch, Redirect } from 'react-router-dom'; import { + ACTUAL_REVENUE_URL, ADD_CUSTOM_EXPENSE_URL, ADD_CUSTOM_REVENUE_URL, ADD_EXPENSE_URL, @@ -82,7 +83,7 @@ const EditCustomRevenue = React.lazy(() => const FinancesRoutes = () => ( - + Date: Wed, 24 Jan 2024 16:06:35 -0300 Subject: [PATCH 2/6] Merge pull request #3089 from LiteFarmOrg/LF-3798/Clicking_the_back_button_on_the_SSO_account_creation_page_takes_you_to_the_welcome_screen LF-3798: Clicking the back button on the SSO account creation page takes you to the welcome screen --- .../api/src/controllers/userFarmController.js | 6 +-- .../webapp/src/containers/ChooseFarm/saga.js | 4 +- .../src/containers/GoogleLoginButton/saga.js | 12 ++---- .../SSOUserCreateAccountInfo/index.jsx | 40 ------------------- .../SSOUserCreateAccountInfo/saga.js | 36 ----------------- packages/webapp/src/main.jsx | 2 - packages/webapp/src/routes/Onboarding.jsx | 3 -- 7 files changed, 6 insertions(+), 97 deletions(-) delete mode 100644 packages/webapp/src/containers/SSOUserCreateAccountInfo/index.jsx delete mode 100644 packages/webapp/src/containers/SSOUserCreateAccountInfo/saga.js diff --git a/packages/api/src/controllers/userFarmController.js b/packages/api/src/controllers/userFarmController.js index d666a07dd1..0768c78966 100644 --- a/packages/api/src/controllers/userFarmController.js +++ b/packages/api/src/controllers/userFarmController.js @@ -45,11 +45,7 @@ const userFarmController = { .leftJoin('farm', 'userFarm.farm_id', 'farm.farm_id'); // TODO find better solution to get owner names const userFarmsWithOwnerField = await appendOwners(rows); - if (!userFarmsWithOwnerField.length) { - res.sendStatus(404); - } else { - res.status(200).send(userFarmsWithOwnerField); - } + res.status(200).send(userFarmsWithOwnerField); } catch (error) { //handle more exceptions res.status(400).send(error); diff --git a/packages/webapp/src/containers/ChooseFarm/saga.js b/packages/webapp/src/containers/ChooseFarm/saga.js index 4cf2680b3c..c237cba721 100644 --- a/packages/webapp/src/containers/ChooseFarm/saga.js +++ b/packages/webapp/src/containers/ChooseFarm/saga.js @@ -46,7 +46,7 @@ export function* getUserFarmsSaga() { yield put(getUserFarmsSuccess(result.data)); } catch (error) { yield put(onLoadingUserFarmsFail(error)); - console.log('failed to fetch task types from database'); + console.log('failed to fetch user farms from database'); } } export const patchUserFarmStatusWithIDToken = createAction('patchUserFarmStatusWithIDTokenSaga'); @@ -76,7 +76,7 @@ export function* getSpotlightFlagsSaga() { yield put(getSpotlightFlagsSuccess(result.data)); } catch (error) { yield put(getSpotlightFlagsFailure()); - console.log('failed to fetch task types from database'); + console.log('failed to fetch spotlight flags from database'); } } diff --git a/packages/webapp/src/containers/GoogleLoginButton/saga.js b/packages/webapp/src/containers/GoogleLoginButton/saga.js index fcb8d8502b..7b574040cb 100644 --- a/packages/webapp/src/containers/GoogleLoginButton/saga.js +++ b/packages/webapp/src/containers/GoogleLoginButton/saga.js @@ -1,7 +1,7 @@ import { createAction } from '@reduxjs/toolkit'; import { call, put, takeLeading } from 'redux-saga/effects'; import { loginUrl as url } from '../../apiConfig'; -import { loginSuccess, onLoadingUserFarmsFail, onLoadingUserFarmsStart } from '../userFarmSlice'; +import { loginSuccess } from '../userFarmSlice'; import history from '../../history'; import i18n from '../../locales/i18n'; import { axios } from '../saga'; @@ -17,7 +17,6 @@ export const loginWithGoogle = createAction(`loginWithGoogleSaga`); export function* loginWithGoogleSaga({ payload: google_id_token }) { try { - yield put(onLoadingUserFarmsStart()); const header = { headers: { 'Content-Type': 'application/json', @@ -36,6 +35,7 @@ export function* loginWithGoogleSaga({ payload: google_id_token }) { if (isInvited) { yield put(setCustomSignUpErrorKey({ key: inlineErrors.invited })); } else if (id_token === '') { + // The user has an account with a password history.push( { pathname: '/', @@ -45,18 +45,12 @@ export function* loginWithGoogleSaga({ payload: google_id_token }) { } else { yield put(loginSuccess(user)); if (isSignUp) { - history.push( - { - pathname: '/sso_signup_information', - }, - { user }, - ); + history.push('/welcome'); } else { history.push('/farm_selection'); } } } catch (e) { - yield put(onLoadingUserFarmsFail(e)); yield put(enqueueErrorSnackbar(i18n.t('message:LOGIN.ERROR.LOGIN_FAIL'))); } } diff --git a/packages/webapp/src/containers/SSOUserCreateAccountInfo/index.jsx b/packages/webapp/src/containers/SSOUserCreateAccountInfo/index.jsx deleted file mode 100644 index b42b95ad8e..0000000000 --- a/packages/webapp/src/containers/SSOUserCreateAccountInfo/index.jsx +++ /dev/null @@ -1,40 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; -import PureCreateUserAccount from '../../components/CreateUserAccount'; - -import { useTranslation } from 'react-i18next'; -import { useDispatch } from 'react-redux'; -import { patchSSOUserInfo } from './saga'; - -export default function SSOUserCreateAccountInfo({ history }) { - const { t } = useTranslation(); - const { user } = history.location.state; - const { email, full_name: name } = user; - const dispatch = useDispatch(); - - const onSignUp = ({ language, ...otherFormData }) => { - dispatch( - patchSSOUserInfo({ user: { ...otherFormData, language_preference: language, email } }), - ); - }; - - const onGoBack = () => { - // TODO LF-3798: Going back (including with browser back button) will not work in this flow as the SSO user account was already created at the point of interacting with the Google Login button - }; - - return ( - - ); -} - -SSOUserCreateAccountInfo.prototype = { - history: PropTypes.object, -}; diff --git a/packages/webapp/src/containers/SSOUserCreateAccountInfo/saga.js b/packages/webapp/src/containers/SSOUserCreateAccountInfo/saga.js deleted file mode 100644 index 8c80b82d78..0000000000 --- a/packages/webapp/src/containers/SSOUserCreateAccountInfo/saga.js +++ /dev/null @@ -1,36 +0,0 @@ -import { createAction } from '@reduxjs/toolkit'; -import { call, select, takeLeading } from 'redux-saga/effects'; -import { url } from '../../apiConfig'; -import { getFirstNameLastName } from '../../util'; -import history from '../../history'; -import { axios } from '../saga'; -import { loginSelector } from '../userFarmSlice'; - -const patchUserUrl = (user_id) => `${url}/user/${user_id}`; - -export const patchSSOUserInfo = createAction(`patchSSOUserInfoSaga`); -export function* patchSSOUserInfoSaga({ payload: { user: userForm } }) { - try { - let { user_id } = yield select(loginSelector); - const id_token = localStorage.getItem('id_token'); - const header = { - headers: { - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + id_token, - }, - }; - const user = { - ...userForm, - ...getFirstNameLastName(userForm.name), - }; - delete user.name; - const result = yield call(axios.put, patchUserUrl(user_id), { ...user }, header); - history.push('/farm_selection'); - } catch (e) { - console.log(e); - } -} - -export default function* SSOInfoSaga() { - yield takeLeading(patchSSOUserInfo.type, patchSSOUserInfoSaga); -} diff --git a/packages/webapp/src/main.jsx b/packages/webapp/src/main.jsx index 393eb8338a..0e16acba4b 100644 --- a/packages/webapp/src/main.jsx +++ b/packages/webapp/src/main.jsx @@ -59,7 +59,6 @@ import { Provider } from 'react-redux'; import { PersistGate } from 'redux-persist/lib/integration/react'; import loginSaga from './containers/GoogleLoginButton/saga'; import inviteSaga from './containers/InvitedUserCreateAccount/saga'; -import SSOInfoSaga from './containers/SSOUserCreateAccountInfo/saga'; import weatherSaga from './containers/WeatherBoard/saga'; import alertSaga from './containers/Navigation/Alert/saga'; import mapSaga from './containers/Map/saga'; @@ -128,7 +127,6 @@ sagaMiddleware.run(loginSaga); sagaMiddleware.run(supportSaga); sagaMiddleware.run(callbackSaga); sagaMiddleware.run(inviteSaga); -sagaMiddleware.run(SSOInfoSaga); sagaMiddleware.run(weatherSaga); sagaMiddleware.run(alertSaga); sagaMiddleware.run(notificationSaga); diff --git a/packages/webapp/src/routes/Onboarding.jsx b/packages/webapp/src/routes/Onboarding.jsx index 7147e8d636..f0ce03740e 100644 --- a/packages/webapp/src/routes/Onboarding.jsx +++ b/packages/webapp/src/routes/Onboarding.jsx @@ -52,8 +52,6 @@ const RequestCertifier = React.lazy(() => import('../containers/OrganicCertifierSurvey/RequestCertifier/OnboardingRequestCertifier'), ); -const SSOUserCreateAccountInfo = React.lazy(() => import('../containers/SSOUserCreateAccountInfo')); - function OnboardingFlow({ step_one, step_two, @@ -72,7 +70,6 @@ function OnboardingFlow({ return ( }> - } /> From 83f60856ec7f5b33dac03f5580be0f7ab4f74d79 Mon Sep 17 00:00:00 2001 From: Duncan-Brain Date: Thu, 25 Jan 2024 09:54:49 -0500 Subject: [PATCH 3/6] Merge pull request #3091 from LiteFarmOrg/LF-4027/Add_gender_and_birth_year_to_user_profile LF-4027: Add gender and birth year to user profile --- .../webapp/public/locales/en/translation.json | 2 +- .../webapp/public/locales/es/translation.json | 2 +- .../webapp/public/locales/pt/translation.json | 2 +- .../components/CreateUserAccount/index.jsx | 8 +-- .../src/components/InviteUser/index.jsx | 8 +-- .../InvitedUserCreateAccount/index.jsx | 8 +-- .../src/components/Profile/Account/index.jsx | 56 ++++++++++++++++--- .../src/components/Profile/EditUser/index.jsx | 8 +-- .../webapp/src/hooks/useGenderOptions.jsx | 28 ++++++++++ .../stories/Pages/Profile/Account.stories.jsx | 3 + 10 files changed, 90 insertions(+), 35 deletions(-) create mode 100644 packages/webapp/src/hooks/useGenderOptions.jsx diff --git a/packages/webapp/public/locales/en/translation.json b/packages/webapp/public/locales/en/translation.json index 876d4d0fba..6a2be0e542 100644 --- a/packages/webapp/public/locales/en/translation.json +++ b/packages/webapp/public/locales/en/translation.json @@ -1345,7 +1345,7 @@ "PHONE_NUMBER": "Phone Number", "PORTUGUESE": "Portuguese", "SPANISH": "Spanish", - "USER_ADDRESS": "User Address" + "USER_ADDRESS": "Address" }, "ACCOUNT_TAB": "Account", "ERROR": { diff --git a/packages/webapp/public/locales/es/translation.json b/packages/webapp/public/locales/es/translation.json index 28149bb6ca..a5bbeffb58 100644 --- a/packages/webapp/public/locales/es/translation.json +++ b/packages/webapp/public/locales/es/translation.json @@ -1346,7 +1346,7 @@ "PHONE_NUMBER": "Número de teléfono", "PORTUGUESE": "Portugués", "SPANISH": "Español", - "USER_ADDRESS": "Dirección de usuario" + "USER_ADDRESS": "Dirección" }, "ACCOUNT_TAB": "Cuenta", "ERROR": { diff --git a/packages/webapp/public/locales/pt/translation.json b/packages/webapp/public/locales/pt/translation.json index d7c6174e9b..2814797f3f 100644 --- a/packages/webapp/public/locales/pt/translation.json +++ b/packages/webapp/public/locales/pt/translation.json @@ -1346,7 +1346,7 @@ "PHONE_NUMBER": "Número de telefone", "PORTUGUESE": "Português", "SPANISH": "Espanhol", - "USER_ADDRESS": "Endereço do usuário" + "USER_ADDRESS": "Endereço" }, "ACCOUNT_TAB": "Conta", "ERROR": { diff --git a/packages/webapp/src/components/CreateUserAccount/index.jsx b/packages/webapp/src/components/CreateUserAccount/index.jsx index 10a943f04c..213a30dadd 100644 --- a/packages/webapp/src/components/CreateUserAccount/index.jsx +++ b/packages/webapp/src/components/CreateUserAccount/index.jsx @@ -10,6 +10,7 @@ import { PasswordError } from '../Form/Errors'; import ReactSelect from '../Form/ReactSelect'; import { useTranslation } from 'react-i18next'; import i18n from '../../locales/i18n'; +import useGenderOptions from '../../hooks/useGenderOptions'; export default function PureCreateUserAccount({ onSignUp, email, onGoBack, isNotSSO }) { const { @@ -39,12 +40,7 @@ export default function PureCreateUserAccount({ onSignUp, email, onGoBack, isNot isTooShort, } = validatePasswordWithErrors(password); - const genderOptions = [ - { value: 'MALE', label: t('gender:MALE') }, - { value: 'FEMALE', label: t('gender:FEMALE') }, - { value: 'OTHER', label: t('gender:OTHER') }, - { value: 'PREFER_NOT_TO_SAY', label: t('gender:PREFER_NOT_TO_SAY') }, - ]; + const genderOptions = useGenderOptions(); const languageOptions = [ { value: 'en', label: t('PROFILE.ACCOUNT.ENGLISH') }, diff --git a/packages/webapp/src/components/InviteUser/index.jsx b/packages/webapp/src/components/InviteUser/index.jsx index 95d1bb0e1b..870a91d6fb 100644 --- a/packages/webapp/src/components/InviteUser/index.jsx +++ b/packages/webapp/src/components/InviteUser/index.jsx @@ -9,6 +9,7 @@ import { Controller, useForm } from 'react-hook-form'; import ReactSelect from '../Form/ReactSelect'; import { useTranslation } from 'react-i18next'; import { getFirstNameLastName } from '../../util'; +import useGenderOptions from '../../hooks/useGenderOptions'; export default function PureInviteUser({ onInvite, onGoBack, userFarmEmails, roleOptions = [] }) { const { @@ -40,12 +41,7 @@ export default function PureInviteUser({ onInvite, onGoBack, userFarmEmails, rol }, [selectedRoleId]); const { t } = useTranslation(['translation', 'common', 'gender']); const title = t('INVITE_USER.TITLE'); - const genderOptions = [ - { value: 'MALE', label: t('gender:MALE') }, - { value: 'FEMALE', label: t('gender:FEMALE') }, - { value: 'OTHER', label: t('gender:OTHER') }, - { value: 'PREFER_NOT_TO_SAY', label: t('gender:PREFER_NOT_TO_SAY') }, - ]; + const genderOptions = useGenderOptions(); const languageOptions = [ { value: 'en', label: t('PROFILE.ACCOUNT.ENGLISH') }, { value: 'es', label: t('PROFILE.ACCOUNT.SPANISH') }, diff --git a/packages/webapp/src/components/InvitedUserCreateAccount/index.jsx b/packages/webapp/src/components/InvitedUserCreateAccount/index.jsx index 81f8bf957d..b8aae36064 100644 --- a/packages/webapp/src/components/InvitedUserCreateAccount/index.jsx +++ b/packages/webapp/src/components/InvitedUserCreateAccount/index.jsx @@ -9,6 +9,7 @@ import ReactSelect from '../Form/ReactSelect'; import Input, { getInputErrors, integerOnKeyDown } from '../Form/Input'; import { PasswordError } from '../Form/Errors'; import { validatePasswordWithErrors } from '../Signup/utils'; +import useGenderOptions from '../../hooks/useGenderOptions'; export default function PureInvitedUserCreateAccountPage({ onSubmit, @@ -44,12 +45,7 @@ export default function PureInvitedUserCreateAccountPage({ }); const { t } = useTranslation(['translation', 'gender']); - const genderOptions = [ - { value: 'MALE', label: t('gender:MALE') }, - { value: 'FEMALE', label: t('gender:FEMALE') }, - { value: 'OTHER', label: t('gender:OTHER') }, - { value: 'PREFER_NOT_TO_SAY', label: t('gender:PREFER_NOT_TO_SAY') }, - ]; + const genderOptions = useGenderOptions(); const validEmailRegex = RegExp(/^$|^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i); const onError = (error) => { diff --git a/packages/webapp/src/components/Profile/Account/index.jsx b/packages/webapp/src/components/Profile/Account/index.jsx index 1892e918a9..a018ab8d9f 100644 --- a/packages/webapp/src/components/Profile/Account/index.jsx +++ b/packages/webapp/src/components/Profile/Account/index.jsx @@ -7,6 +7,7 @@ import React, { useEffect, useRef } from 'react'; import Button from '../../Form/Button'; import PropTypes from 'prop-types'; import ProfileLayout from '../ProfileLayout'; +import useGenderOptions from '../../../hooks/useGenderOptions'; const useLanguageOptions = (language_preference) => { const { t } = useTranslation(); @@ -23,6 +24,7 @@ const useLanguageOptions = (language_preference) => { }; export default function PureAccount({ userFarm, onSubmit, history, isAdmin }) { + const genderOptions = useGenderOptions(); const { languageOptions, languagePreferenceOptionRef } = useLanguageOptions( userFarm.language_preference, ); @@ -35,7 +37,12 @@ export default function PureAccount({ userFarm, onSubmit, history, isAdmin }) { formState: { isValid, isDirty, errors }, } = useForm({ mode: 'onChange', - defaultValues: userFarm, + defaultValues: { + ...userFarm, + [userFarmEnum.gender]: genderOptions.find( + ({ value }) => value === userFarm[userFarmEnum.gender], + ), + }, shouldUnregister: true, }); useEffect(() => { @@ -90,13 +97,6 @@ export default function PureAccount({ userFarm, onSubmit, history, isAdmin }) { errors={errors[userFarmEnum.phone_number] && errors[userFarmEnum.phone_number].message} optional /> - ( - - )} - /> + + ( + + )} + /> + ( + + )} + /> ); } @@ -116,6 +153,9 @@ PureAccount.propTypes = { email: PropTypes.string, phone_number: PropTypes.string, user_address: PropTypes.string, + language_preference: PropTypes.string, + gender: PropTypes.oneOf(['MALE', 'FEMALE', 'OTHER', 'PREFER_NOT_TO_SAY']), + birth_year: PropTypes.number, }).isRequired, onSubmit: PropTypes.func, }; diff --git a/packages/webapp/src/components/Profile/EditUser/index.jsx b/packages/webapp/src/components/Profile/EditUser/index.jsx index eddb70b355..cc301f36d4 100644 --- a/packages/webapp/src/components/Profile/EditUser/index.jsx +++ b/packages/webapp/src/components/Profile/EditUser/index.jsx @@ -12,6 +12,7 @@ import InvalidRevokeUserAccessModal from '../../Modals/InvalidRevokeUserAccessMo import Checkbox from '../../Form/Checkbox'; import { useSelector } from 'react-redux'; import { userFarmsByFarmSelector } from '../../../containers/userFarmSlice'; +import useGenderOptions from '../../../hooks/useGenderOptions'; export default function PureEditUser({ userFarm, @@ -41,12 +42,7 @@ export default function PureEditUser({ const userFarms = useSelector(userFarmsByFarmSelector); const adminRoles = [1, 2, 5]; - const genderOptions = [ - { value: 'MALE', label: t('gender:MALE') }, - { value: 'FEMALE', label: t('gender:FEMALE') }, - { value: 'OTHER', label: t('gender:OTHER') }, - { value: 'PREFER_NOT_TO_SAY', label: t('gender:PREFER_NOT_TO_SAY') }, - ]; + const genderOptions = useGenderOptions(); const languageOptions = [ { value: 'en', label: t('PROFILE.ACCOUNT.ENGLISH') }, { value: 'es', label: t('PROFILE.ACCOUNT.SPANISH') }, diff --git a/packages/webapp/src/hooks/useGenderOptions.jsx b/packages/webapp/src/hooks/useGenderOptions.jsx new file mode 100644 index 0000000000..cf7713dd0f --- /dev/null +++ b/packages/webapp/src/hooks/useGenderOptions.jsx @@ -0,0 +1,28 @@ +/* + * Copyright 2024 LiteFarm.org + * This file is part of LiteFarm. + * + * LiteFarm is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiteFarm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details, see . + */ +import { useTranslation } from 'react-i18next'; + +const useGenderOptions = () => { + const { t } = useTranslation(); + + return [ + { value: 'MALE', label: t('gender:MALE') }, + { value: 'FEMALE', label: t('gender:FEMALE') }, + { value: 'OTHER', label: t('gender:OTHER') }, + { value: 'PREFER_NOT_TO_SAY', label: t('gender:PREFER_NOT_TO_SAY') }, + ]; +}; + +export default useGenderOptions; diff --git a/packages/webapp/src/stories/Pages/Profile/Account.stories.jsx b/packages/webapp/src/stories/Pages/Profile/Account.stories.jsx index 88bcfc24c4..e480b186d1 100644 --- a/packages/webapp/src/stories/Pages/Profile/Account.stories.jsx +++ b/packages/webapp/src/stories/Pages/Profile/Account.stories.jsx @@ -20,6 +20,9 @@ Primary.args = { email: 'example@litefarm.org', phone_number: '123456789', user_address: 'litefarm', + language_preference: 'fr', + gender: 'MALE', + birth_year: 2000, }, }; Primary.parameters = { From b151027321ded9159cafc494fe96c1cf5cfbd7ea Mon Sep 17 00:00:00 2001 From: Duncan-Brain Date: Thu, 25 Jan 2024 16:09:37 -0500 Subject: [PATCH 4/6] Merge pull request #3092 from LiteFarmOrg/LF-4037-SSO-account-cannot-be-created-without-last-name LF-4037: add default to last name --- ...240125135642_add_user_last_name_default.js | 26 +++++++++++++++++++ .../api/src/controllers/loginController.js | 1 + packages/api/src/models/userModel.js | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 packages/api/db/migration/20240125135642_add_user_last_name_default.js diff --git a/packages/api/db/migration/20240125135642_add_user_last_name_default.js b/packages/api/db/migration/20240125135642_add_user_last_name_default.js new file mode 100644 index 0000000000..baf326c8de --- /dev/null +++ b/packages/api/db/migration/20240125135642_add_user_last_name_default.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2024 LiteFarm.org + * This file is part of LiteFarm. + * + * LiteFarm is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LiteFarm is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details, see . + */ + +export const up = async function (knex) { + await knex.schema.alterTable('users', (table) => { + table.string('last_name').notNullable().defaultTo('').alter(); + }); +}; + +export const down = async function (knex) { + await knex.schema.alterTable('users', (table) => { + table.string('last_name').notNullable().defaultTo(null).alter(); + }); +}; diff --git a/packages/api/src/controllers/loginController.js b/packages/api/src/controllers/loginController.js index fb229b7e12..260b7ed0a3 100644 --- a/packages/api/src/controllers/loginController.js +++ b/packages/api/src/controllers/loginController.js @@ -158,6 +158,7 @@ const loginController = { isInvited: user?.status_id === 2, }); } catch (err) { + console.error(err); return res.status(400).json({ err, }); diff --git a/packages/api/src/models/userModel.js b/packages/api/src/models/userModel.js index fa8937a269..3fddc84ab3 100644 --- a/packages/api/src/models/userModel.js +++ b/packages/api/src/models/userModel.js @@ -85,7 +85,7 @@ class User extends Model { static get jsonSchema() { return { type: 'object', - required: ['first_name', 'last_name', 'email'], + required: ['first_name', 'email'], properties: { user_id: { type: 'string' }, From 2aa83f8fd312324e5d9f8f1a04af14c4a4b0d103 Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Fri, 26 Jan 2024 13:35:26 -0300 Subject: [PATCH 5/6] update version number --- packages/api/package-lock.json | 2 +- packages/api/package.json | 2 +- packages/api/src/server.js | 2 +- packages/webapp/package.json | 2 +- packages/webapp/src/main.jsx | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/api/package-lock.json b/packages/api/package-lock.json index 033513f82b..01481f6dfc 100644 --- a/packages/api/package-lock.json +++ b/packages/api/package-lock.json @@ -1,6 +1,6 @@ { "name": "litefarm-api", - "version": "3.6.2", + "version": "3.6.3", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/packages/api/package.json b/packages/api/package.json index 8541373e02..dc61c37e36 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -1,6 +1,6 @@ { "name": "litefarm-api", - "version": "3.6.2", + "version": "3.6.3", "description": "LiteFarm API server", "main": "./api/src/server.js", "type": "module", diff --git a/packages/api/src/server.js b/packages/api/src/server.js index 691bbf0308..39f4832508 100644 --- a/packages/api/src/server.js +++ b/packages/api/src/server.js @@ -39,7 +39,7 @@ if (process.env.SENTRY_DSN && environment !== 'development') { // Automatically instrument Node.js libraries and frameworks ...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(), ], - release: '3.6.2', + release: '3.6.3', // Set tracesSampleRate to 1.0 to capture 100% // of transactions for performance monitoring. // We recommend adjusting this value in production diff --git a/packages/webapp/package.json b/packages/webapp/package.json index 32a97e6a03..6919683993 100644 --- a/packages/webapp/package.json +++ b/packages/webapp/package.json @@ -1,6 +1,6 @@ { "name": "litefarm-webapp", - "version": "3.6.2", + "version": "3.6.3", "description": "LiteFarm Web application", "type": "module", "scripts": { diff --git a/packages/webapp/src/main.jsx b/packages/webapp/src/main.jsx index 0e16acba4b..90f7623b4d 100644 --- a/packages/webapp/src/main.jsx +++ b/packages/webapp/src/main.jsx @@ -85,7 +85,7 @@ if (import.meta.env.VITE_SENTRY_DSN) { Sentry.init({ dsn: import.meta.env.VITE_SENTRY_DSN, integrations: [new Integrations.BrowserTracing()], - release: '3.6.2', + release: '3.6.3', // Set tracesSampleRate to 1.0 to capture 100% // of transactions for performance monitoring. // We recommend adjusting this value in production From 64830b4b5e28353735446f3bb771b779b0933aa2 Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Tue, 30 Jan 2024 10:20:43 -0300 Subject: [PATCH 6/6] Merge pull request #3098 from LiteFarmOrg/LF-4038/The_app_crashes_on_the_home_page_once_the_user_saves_the_user_profile_without_preferred_language LF-4038: The app crashes on the home page once the user saves the user profile without preferred language --- packages/webapp/src/components/Profile/Account/index.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/webapp/src/components/Profile/Account/index.jsx b/packages/webapp/src/components/Profile/Account/index.jsx index a018ab8d9f..5738fea19e 100644 --- a/packages/webapp/src/components/Profile/Account/index.jsx +++ b/packages/webapp/src/components/Profile/Account/index.jsx @@ -19,7 +19,8 @@ const useLanguageOptions = (language_preference) => { }; const languageOptions = Object.values(languageOptionMap); const languagePreferenceOptionRef = useRef(); - languagePreferenceOptionRef.current = languageOptionMap[language_preference]; + languagePreferenceOptionRef.current = + languageOptionMap[language_preference] || language_preference; return { languageOptionMap, languageOptions, languagePreferenceOptionRef }; }; @@ -46,6 +47,7 @@ export default function PureAccount({ userFarm, onSubmit, history, isAdmin }) { shouldUnregister: true, }); useEffect(() => { + // get proper translations for the selected options right after language preference is updated setValue(userFarmEnum.language_preference, null, { shouldValidate: false, shouldDirty: false }); setTimeout(() => { setValue(userFarmEnum.language_preference, languagePreferenceOptionRef.current, { @@ -80,6 +82,7 @@ export default function PureAccount({ userFarm, onSubmit, history, isAdmin }) { maxLength: { value: 255, message: t('PROFILE.ERROR.LAST_NAME_LENGTH') }, })} errors={errors[userFarmEnum.last_name] && errors[userFarmEnum.last_name].message} + optional />