Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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.11.0",
"version": "3.11.1",
"description": "LiteFarm API server",
"main": "./api/src/server.js",
"type": "module",
Expand Down
8 changes: 3 additions & 5 deletions packages/api/src/controllers/userFarmController.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,10 @@ const userFarmController = {
return async (req, res) => {
let result;
const { user_id, farm_id } = req.auth;
const { language_preference } = req.body;

// A new invitee has a uuid id and no password record yet
if (!/^\d+$/.test(user_id)) {
const user = await UserModel.query()
.findById(user_id)
.patch({ language_preference })
.returning('*');
const user = await UserModel.query().findById(user_id);
const passwordRow = await PasswordModel.query().findById(user_id);
if (!passwordRow || user.status_id === 2) {
return res.status(404).send('User does not exist');
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/models/emailTokenModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class emailTokenModel extends Model {
token = await createToken('invite', {
...user,
...userFarm,
language_preference: user.language_preference,
invitation_id: emailToken.invitation_id,
});
} else {
Expand All @@ -105,6 +106,7 @@ class emailTokenModel extends Model {
token = await createToken('invite', {
...user,
...userFarm,
language_preference: user.language_preference,
invitation_id: emailToken.invitation_id,
});
}
Expand All @@ -121,7 +123,7 @@ class emailTokenModel extends Model {
user.email,
{
sender,
buttonLink: `/callback/?invite_token=${token}&language=${user.language_preference}`,
buttonLink: `/callback/?invite_token=${token}`,
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (process.env.SENTRY_DSN && environment !== 'development') {
// Automatically instrument Node.js libraries and frameworks
...Sentry.autoDiscoverNodePerformanceMonitoringIntegrations(),
],
release: '3.11.0',
release: '3.11.1',
// 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.11.0",
"version": "3.11.1",
"description": "LiteFarm Web application",
"type": "module",
"devEngines": {
Expand Down
1 change: 0 additions & 1 deletion packages/webapp/src/containers/Callback/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ function Callback() {
dispatch(
patchUserFarmStatus({
invite_token: params.get('invite_token'),
language: params.get('language'),
}),
);
} else {
Expand Down
16 changes: 11 additions & 5 deletions packages/webapp/src/containers/Callback/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function* validateResetTokenSaga({ payload: { reset_token } }) {
export const patchUserFarmStatus = createAction('patchUserFarmStatusSaga');

export function* patchUserFarmStatusSaga({ payload }) {
const { invite_token, language } = payload;
const { invite_token } = payload;
try {
const result = yield call(
axios.patch,
Expand All @@ -65,17 +65,23 @@ export function* patchUserFarmStatusSaga({ payload }) {
const { user: userFarm, id_token } = result.data;
localStorage.setItem('id_token', id_token);
localStorage.setItem('litefarm_lang', userFarm.language_preference);
i18n.changeLanguage(userFarm.language_preference);
const requestedLang = getLanguageFromLocalStorage();
const targetLang = i18n.options.supportedLngs?.includes(requestedLang) ? requestedLang : 'en';
if (i18n.language !== targetLang) {
i18n.changeLanguage(targetLang);
}
purgeState();
yield put(acceptInvitationSuccess(userFarm));
yield put(startInvitationFlow(userFarm.farm_id));
history.push('/consent');
} catch (e) {
if (e?.response?.status === 404) {
// and message === 'user does not exist
console.log(e);
// user does not exist yet; the invite token carries the sender's selected language
const language = decodeToken(invite_token)?.language_preference || 'en';
localStorage.setItem('litefarm_lang', language);
i18n.changeLanguage(language);
if (i18n.language !== language) {
i18n.changeLanguage(language);
}
history.push('/accept_invitation/sign_up', invite_token);
} else if (e?.response?.status === 401) {
const { email: currentEmail } = yield select(userFarmSelector);
Expand Down
6 changes: 4 additions & 2 deletions packages/webapp/src/containers/GoogleLoginButton/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export function* loginWithGoogleSaga({ payload: google_id_token }) {
const { id_token, user, isSignUp, isInvited } = result.data;
localStorage.setItem('id_token', id_token);
localStorage.setItem('litefarm_lang', user.language_preference);
if (i18n.language !== getLanguageFromLocalStorage()) {
i18n.changeLanguage(getLanguageFromLocalStorage());
const requestedLang = getLanguageFromLocalStorage();
const targetLang = i18n.options.supportedLngs?.includes(requestedLang) ? requestedLang : 'en';
if (i18n.language !== targetLang) {
i18n.changeLanguage(targetLang);
}
if (isInvited) {
yield put(setCustomSignUpErrorKey({ key: inlineErrors.invited }));
Expand Down
2 changes: 1 addition & 1 deletion packages/webapp/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ if (import.meta.env.VITE_SENTRY_DSN) {
Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
integrations: [new Integrations.BrowserTracing()],
release: '3.11.0',
release: '3.11.1',
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
Expand Down
13 changes: 9 additions & 4 deletions packages/webapp/src/routes/Onboarding.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
/* eslint-disable react/no-children-prop */
import React from 'react';
import { Redirect, Route, Switch } from 'react-router-dom';

import { useSelector } from 'react-redux';
import { userFarmLengthSelector } from '../containers/userFarmSlice';
import { userFarmLengthSelector, userFarmStatusSelector } from '../containers/userFarmSlice';
import { hookFormPersistSelector } from '../containers/hooks/useHookFormPersist/hookFormPersistSlice';

const RoleSelection = React.lazy(() => import('../containers/RoleSelection'));
Expand Down Expand Up @@ -65,8 +64,9 @@ function OnboardingFlow(props) {
);

const hasUserFarms = useSelector(userFarmLengthSelector);
const { loaded: farmsLoaded } = useSelector(userFarmStatusSelector);

const requireConditionProps = { ...props, hasUserFarms };
const requireConditionProps = { ...props, hasUserFarms, farmsLoaded };

return (
<Switch>
Expand Down Expand Up @@ -174,6 +174,7 @@ const RequireCondition = ({
has_consent,
farm_id,
hasUserFarms,
farmsLoaded,
}) => {
if (condition) {
return children;
Expand All @@ -196,7 +197,11 @@ const RequireCondition = ({
}

if ((!farm_id || !step_one) && !hasUserFarms) {
return <Redirect to="/welcome" />;
// hasUserFarms === 0 is ambiguous ("no farms" vs "list not fetched yet");
// only treat it as "no farms" once the list has loaded, else route to /farm_selection,
// where ChooseFarm owns the "no farms -> /welcome" decision.
const target = farmsLoaded ? '/welcome' : '/farm_selection';
return <Redirect to={target} />;
}

if (!farm_id && hasUserFarms) {
Expand Down
Loading