Skip to content

Commit

Permalink
Merge pull request #3095 from LiteFarmOrg/hotfix/3.6.3
Browse files Browse the repository at this point in the history
Hotfix 3.6.3
  • Loading branch information
antsgar authored Jan 30, 2024
2 parents d8919c4 + 64830b4 commit 9923733
Show file tree
Hide file tree
Showing 28 changed files with 144 additions and 143 deletions.
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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();
});
};
2 changes: 1 addition & 1 deletion packages/api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/controllers/loginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ const loginController = {
isInvited: user?.status_id === 2,
});
} catch (err) {
console.error(err);
return res.status(400).json({
err,
});
Expand Down
6 changes: 1 addition & 5 deletions packages/api/src/controllers/userFarmController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/models/userModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "litefarm-webapp",
"version": "3.6.2",
"version": "3.6.3",
"description": "LiteFarm Web application",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@
"PHONE_NUMBER": "Phone Number",
"PORTUGUESE": "Portuguese",
"SPANISH": "Spanish",
"USER_ADDRESS": "User Address"
"USER_ADDRESS": "Address"
},
"ACCOUNT_TAB": "Account",
"ERROR": {
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/public/locales/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/public/locales/pt/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 2 additions & 6 deletions packages/webapp/src/components/CreateUserAccount/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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') },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -84,7 +85,7 @@ const FinancesCarrousel = ({
<div className={styles.revenueExpensesContainer}>
<TextButton
className={clsx([styles.revenueContainer, styles.clickableContainer])}
onClick={() => history.push('/finances/actual_revenue')}
onClick={() => history.push(ACTUAL_REVENUE_URL)}
>
<span>
<span className={styles.revenueTitle}>{t('SALE.FINANCES.TOTAL_REVENUE')}</span>
Expand Down
8 changes: 2 additions & 6 deletions packages/webapp/src/components/InviteUser/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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') },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) => {
Expand Down
61 changes: 52 additions & 9 deletions packages/webapp/src/components/Profile/Account/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -18,11 +19,13 @@ 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 };
};

export default function PureAccount({ userFarm, onSubmit, history, isAdmin }) {
const genderOptions = useGenderOptions();
const { languageOptions, languagePreferenceOptionRef } = useLanguageOptions(
userFarm.language_preference,
);
Expand All @@ -35,10 +38,16 @@ 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(() => {
// 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, {
Expand Down Expand Up @@ -73,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
/>
<Input
label={t('PROFILE.ACCOUNT.EMAIL')}
Expand All @@ -90,13 +100,6 @@ export default function PureAccount({ userFarm, onSubmit, history, isAdmin }) {
errors={errors[userFarmEnum.phone_number] && errors[userFarmEnum.phone_number].message}
optional
/>
<Controller
control={control}
name={userFarmEnum.language_preference}
render={({ field }) => (
<ReactSelect label={t('PROFILE.ACCOUNT.LANGUAGE')} options={languageOptions} {...field} />
)}
/>
<Input
label={t('PROFILE.ACCOUNT.USER_ADDRESS')}
hookFormRegister={register(userFarmEnum.user_address, {
Expand All @@ -106,6 +109,43 @@ export default function PureAccount({ userFarm, onSubmit, history, isAdmin }) {
errors={errors[userFarmEnum.user_address] && errors[userFarmEnum.user_address].message}
optional
/>
<Input
label={t('CREATE_USER.BIRTH_YEAR')}
type="number"
onKeyPress={integerOnKeyDown}
hookFormRegister={register(userFarmEnum.birth_year, {
min: 1900,
max: new Date().getFullYear(),
valueAsNumber: true,
})}
toolTipContent={t('CREATE_USER.BIRTH_YEAR_TOOLTIP')}
errors={
errors[userFarmEnum.birth_year] &&
(errors[userFarmEnum.birth_year].message ||
`${t('CREATE_USER.BIRTH_YEAR_ERROR')} ${new Date().getFullYear()}`)
}
optional
/>
<Controller
control={control}
name={userFarmEnum.gender}
render={({ field: { onChange, value } }) => (
<ReactSelect
label={t('CREATE_USER.GENDER')}
options={genderOptions}
onChange={onChange}
value={value}
toolTipContent={t('CREATE_USER.GENDER_TOOLTIP')}
/>
)}
/>
<Controller
control={control}
name={userFarmEnum.language_preference}
render={({ field }) => (
<ReactSelect label={t('PROFILE.ACCOUNT.LANGUAGE')} options={languageOptions} {...field} />
)}
/>
</ProfileLayout>
);
}
Expand All @@ -116,6 +156,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,
};
8 changes: 2 additions & 6 deletions packages/webapp/src/components/Profile/EditUser/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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') },
Expand Down
4 changes: 2 additions & 2 deletions packages/webapp/src/containers/ChooseFarm/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
}
}

Expand Down
Loading

0 comments on commit 9923733

Please sign in to comment.