Compare commits

...

3 Commits

Author SHA1 Message Date
Ahmed Bouhuolia
1227111fae fix: typo 2024-05-18 15:44:53 +02:00
Ahmed Bouhuolia
2ada57a2b4 fix: auto-increment setting parsing. (#453) 2024-05-17 12:49:04 +02:00
Ahmed Bouhuolia
e380c598d3 fix: Showing the real mail address on email confirmation view (#445)
* fix: Showing the real mail address on email confirmation view

* chore: remove the unused hook
2024-05-15 14:03:58 +02:00
13 changed files with 183 additions and 45 deletions

View File

@@ -1,4 +1,4 @@
import { difference } from 'lodash'; import { difference, isEmpty } from 'lodash';
import { Service, Inject } from 'typedi'; import { Service, Inject } from 'typedi';
import { ServiceError } from '@/exceptions'; import { ServiceError } from '@/exceptions';
import { import {
@@ -244,16 +244,12 @@ export class CommandManualJournalValidators {
/** /**
* Validates the manual journal number require. * Validates the manual journal number require.
* @param {string} journalNumber * @param {string} journalNumber
* @throws {ServiceError(ERRORS.MANUAL_JOURNAL_NO_REQUIRED)}
*/ */
public validateJournalNoRequireWhenAutoNotEnabled = ( public validateJournalNoRequireWhenAutoNotEnabled = (
tenantId: number,
journalNumber: string journalNumber: string
) => { ) => {
// Retrieve the next manual journal number. if (isEmpty(journalNumber)) {
const autoIncrmenetEnabled =
this.autoIncrement.autoIncrementEnabled(tenantId);
if (!journalNumber || !autoIncrmenetEnabled) {
throw new ServiceError(ERRORS.MANUAL_JOURNAL_NO_REQUIRED); throw new ServiceError(ERRORS.MANUAL_JOURNAL_NO_REQUIRED);
} }
}; };

View File

@@ -99,7 +99,6 @@ export class CreateManualJournalService {
// Validate manual journal number require when auto-increment not enabled. // Validate manual journal number require when auto-increment not enabled.
this.validator.validateJournalNoRequireWhenAutoNotEnabled( this.validator.validateJournalNoRequireWhenAutoNotEnabled(
tenantId,
manualJournalDTO.journalNumber manualJournalDTO.journalNumber
); );
// Validate manual journal uniquiness on the storage. // Validate manual journal uniquiness on the storage.

View File

@@ -15,10 +15,8 @@ export default class AutoIncrementOrdersService {
const group = settingsGroup; const group = settingsGroup;
// Settings service transaction number and prefix. // Settings service transaction number and prefix.
const autoIncrement = settings.get({ group, key: 'auto_increment' }, false); return settings.get({ group, key: 'auto_increment' }, false);
};
return parseBoolean(autoIncrement, false);
}
/** /**
* Retrieve the next service transaction number. * Retrieve the next service transaction number.
@@ -27,17 +25,16 @@ export default class AutoIncrementOrdersService {
* @param {Function} getMaxTransactionNo * @param {Function} getMaxTransactionNo
* @return {Promise<string>} * @return {Promise<string>}
*/ */
getNextTransactionNumber(tenantId: number, settingsGroup: string): string { getNextTransactionNumber(tenantId: number, group: string): string {
const settings = this.tenancy.settings(tenantId); const settings = this.tenancy.settings(tenantId);
const group = settingsGroup;
// Settings service transaction number and prefix. // Settings service transaction number and prefix.
const autoIncrement = settings.get({ group, key: 'auto_increment' }, false); const autoIncrement = this.autoIncrementEnabled(tenantId, group);
const settingNo = settings.get({ group, key: 'next_number' }, ''); const settingNo = settings.get({ group, key: 'next_number' }, '');
const settingPrefix = settings.get({ group, key: 'number_prefix' }, ''); const settingPrefix = settings.get({ group, key: 'number_prefix' }, '');
return parseBoolean(autoIncrement, false) ? `${settingPrefix}${settingNo}` : ''; return autoIncrement ? `${settingPrefix}${settingNo}` : '';
} }
/** /**
@@ -53,7 +50,9 @@ export default class AutoIncrementOrdersService {
const autoIncrement = settings.get({ group, key: 'auto_increment' }); const autoIncrement = settings.get({ group, key: 'auto_increment' });
// Can't continue if the auto-increment of the service was disabled. // Can't continue if the auto-increment of the service was disabled.
if (!autoIncrement) { return; } if (!autoIncrement) {
return;
}
settings.set( settings.set(
{ group, key: 'next_number' }, { group, key: 'next_number' },

View File

@@ -337,6 +337,9 @@ const booleanValues: string[] = [
].map((value) => normalizeValue(value)); ].map((value) => normalizeValue(value));
export const parseBoolean = <T>(value: any, defaultValue: T): T | boolean => { export const parseBoolean = <T>(value: any, defaultValue: T): T | boolean => {
if (typeof value === 'boolean') {
return value; // Retrun early we have nothing to parse.
}
const normalizedValue = normalizeValue(value); const normalizedValue = normalizeValue(value);
if (isEmpty(value) || booleanValues.indexOf(normalizedValue) === -1) { if (isEmpty(value) || booleanValues.indexOf(normalizedValue) === -1) {
return defaultValue; return defaultValue;

View File

@@ -9,7 +9,11 @@ import AuthInsider from '@/containers/Authentication/AuthInsider';
import { useAuthLogin, useAuthRegister } from '@/hooks/query/authentication'; import { useAuthLogin, useAuthRegister } from '@/hooks/query/authentication';
import RegisterForm from './RegisterForm'; import RegisterForm from './RegisterForm';
import { RegisterSchema, transformRegisterErrorsToForm, transformRegisterToastMessages } from './utils'; import {
RegisterSchema,
transformRegisterErrorsToForm,
transformRegisterToastMessages,
} from './utils';
import { import {
AuthFooterLinks, AuthFooterLinks,
AuthFooterLink, AuthFooterLink,
@@ -32,7 +36,7 @@ export default function RegisterUserForm() {
const handleSubmit = (values, { setSubmitting, setErrors }) => { const handleSubmit = (values, { setSubmitting, setErrors }) => {
authRegisterMutate(values) authRegisterMutate(values)
.then((response) => { .then(() => {
authLoginMutate({ authLoginMutate({
crediential: values.email, crediential: values.email,
password: values.password, password: values.password,
@@ -87,7 +91,10 @@ function RegisterFooterLinks() {
return ( return (
<AuthFooterLinks> <AuthFooterLinks>
<AuthFooterLink> <AuthFooterLink>
<T id={'return_to'} /> <Link to={'/auth/login'}><T id={'sign_in'} /></Link> <T id={'return_to'} />{' '}
<Link to={'/auth/login'}>
<T id={'sign_in'} />
</Link>
</AuthFooterLink> </AuthFooterLink>
<AuthFooterLink> <AuthFooterLink>

View File

@@ -4,7 +4,7 @@ import AuthInsider from './AuthInsider';
import { AuthInsiderCard } from './_components'; import { AuthInsiderCard } from './_components';
import styles from './RegisterVerify.module.scss'; import styles from './RegisterVerify.module.scss';
import { AppToaster, Stack } from '@/components'; import { AppToaster, Stack } from '@/components';
import { useAuthActions } from '@/hooks/state'; import { useAuthActions, useAuthUserVerifyEmail } from '@/hooks/state';
import { useAuthSignUpVerifyResendMail } from '@/hooks/query'; import { useAuthSignUpVerifyResendMail } from '@/hooks/query';
import { AuthContainer } from './AuthContainer'; import { AuthContainer } from './AuthContainer';
@@ -13,6 +13,8 @@ export default function RegisterVerify() {
const { mutateAsync: resendSignUpVerifyMail, isLoading } = const { mutateAsync: resendSignUpVerifyMail, isLoading } =
useAuthSignUpVerifyResendMail(); useAuthSignUpVerifyResendMail();
const emailAddress = useAuthUserVerifyEmail();
const handleResendMailBtnClick = () => { const handleResendMailBtnClick = () => {
resendSignUpVerifyMail() resendSignUpVerifyMail()
.then(() => { .then(() => {
@@ -38,8 +40,8 @@ export default function RegisterVerify() {
<AuthInsiderCard className={styles.root}> <AuthInsiderCard className={styles.root}>
<h2 className={styles.title}>Please verify your email</h2> <h2 className={styles.title}>Please verify your email</h2>
<p className={styles.description}> <p className={styles.description}>
We sent an email to <strong>asdahmed@gmail.com</strong> Click the We sent an email to <strong>{emailAddress}</strong> Click the link
link inside to get started. inside to get started.
</p> </p>
<Stack spacing={4}> <Stack spacing={4}>

View File

@@ -1,10 +1,8 @@
// @ts-nocheck // @ts-nocheck
import { T } from '@/components'; import { Callout } from '@blueprintjs/core';
import { SubscriptionPlans } from './SubscriptionPlan'; import { SubscriptionPlans } from './SubscriptionPlan';
import withPlans from '../../Subscriptions/withPlans'; import withPlans from '../../Subscriptions/withPlans';
import { compose } from '@/utils'; import { compose } from '@/utils';
import { Callout, Intent } from '@blueprintjs/core';
/** /**
* Billing plans. * Billing plans.
@@ -15,10 +13,11 @@ function SubscriptionPlansSectionRoot({ plans }) {
<Callout <Callout
style={{ marginBottom: '1.5rem' }} style={{ marginBottom: '1.5rem' }}
icon={null} icon={null}
title={'Early Adaptors Plan'} title={'Early Adopter Plan'}
> >
We're looking for 200 early adaptors, when you subscribe you'll get We're looking for 200 early adopters, when you subscribe you'll get the
the full features and unlimited users for a year regardless of the subscribed plan. full features and unlimited users for a year regardless of the
subscribed plan.
</Callout> </Callout>
<SubscriptionPlans plans={plans} /> <SubscriptionPlans plans={plans} />
</section> </section>

View File

@@ -1,9 +1,17 @@
// @ts-nocheck // @ts-nocheck
import { useMutation } from 'react-query'; import { useMutation } from 'react-query';
import { batch } from 'react-redux';
import useApiRequest from '../useRequest'; import useApiRequest from '../useRequest';
import { setCookie } from '../../utils'; import { setCookie } from '../../utils';
import { useRequestQuery } from '../useQueryRequest'; import { useRequestQuery } from '../useQueryRequest';
import t from './types'; import t from './types';
import {
useSetAuthToken,
useSetAuthUserId,
useSetLocale,
useSetOrganizationId,
useSetTenantId,
} from '../state';
/** /**
* Saves the response data to cookies. * Saves the response data to cookies.
@@ -24,14 +32,30 @@ function setAuthLoginCookies(data) {
export const useAuthLogin = (props) => { export const useAuthLogin = (props) => {
const apiRequest = useApiRequest(); const apiRequest = useApiRequest();
const setAuthToken = useSetAuthToken();
const setOrganizationId = useSetOrganizationId();
const setUserId = useSetAuthUserId();
const setTenantId = useSetTenantId();
const setLocale = useSetLocale();
return useMutation((values) => apiRequest.post('auth/login', values), { return useMutation((values) => apiRequest.post('auth/login', values), {
select: (res) => res.data, select: (res) => res.data,
onSuccess: (data) => { onSuccess: (res) => {
// Set authentication cookies. // Set authentication cookies.
setAuthLoginCookies(data.data); setAuthLoginCookies(res.data);
// Reboot the application. batch(() => {
window.location.reload(); // Sets the auth metadata to global state.
setAuthToken(res.data.token);
setOrganizationId(res.data.tenant.organization_id);
setUserId(res.data.user.id);
setTenantId(res.data.tenant.id);
if (res.data?.tenant?.metadata?.language) {
setLocale(res.data?.tenant?.metadata?.language);
}
});
props?.onSuccess && props?.onSuccess(...args);
}, },
...props, ...props,
}); });

View File

@@ -1,7 +1,7 @@
// @ts-nocheck // @ts-nocheck
import { useEffect } from 'react'; import { useEffect } from 'react';
import { useMutation, useQueryClient } from 'react-query'; import { useMutation, useQueryClient } from 'react-query';
import { useQueryTenant, useRequestQuery } from '../useQueryRequest'; import { useRequestQuery } from '../useQueryRequest';
import useApiRequest from '../useRequest'; import useApiRequest from '../useRequest';
import { useSetFeatureDashboardMeta } from '../state/feature'; import { useSetFeatureDashboardMeta } from '../state/feature';
import t from './types'; import t from './types';
@@ -143,7 +143,7 @@ export function useAuthenticatedAccount(props) {
select: (response) => response.data.data, select: (response) => response.data.data,
defaultData: {}, defaultData: {},
onSuccess: (data) => { onSuccess: (data) => {
setEmailConfirmed(data.is_verified); setEmailConfirmed(data.is_verified, data.email);
}, },
...props, ...props,
}, },

View File

@@ -3,8 +3,13 @@ import { useDispatch, useSelector } from 'react-redux';
import { useCallback } from 'react'; import { useCallback } from 'react';
import { isAuthenticated } from '@/store/authentication/authentication.reducer'; import { isAuthenticated } from '@/store/authentication/authentication.reducer';
import { import {
setAuthTenantId,
setAuthToken,
setAuthUserId,
setEmailConfirmed, setEmailConfirmed,
setLogin, setLogin,
setOrganizationId,
setLocale,
} from '@/store/authentication/authentication.actions'; } from '@/store/authentication/authentication.actions';
import { useQueryClient } from 'react-query'; import { useQueryClient } from 'react-query';
import { removeCookie } from '@/utils'; import { removeCookie } from '@/utils';
@@ -75,6 +80,14 @@ export const useAuthUserVerified = () => {
return useSelector((state) => state.authentication.verified); return useSelector((state) => state.authentication.verified);
}; };
/**
* Retrieves the user's email address.
* @returns {string}
*/
export const useAuthUserVerifyEmail = () => {
return useSelector((state) => state.authentication.verifyEmail);
};
/** /**
* Sets the user's email verification status. * Sets the user's email verification status.
*/ */
@@ -82,7 +95,53 @@ export const useSetAuthEmailConfirmed = () => {
const dispatch = useDispatch(); const dispatch = useDispatch();
return useCallback( return useCallback(
(verified?: boolean = true) => dispatch(setEmailConfirmed(verified)), (verified?: boolean = true, email: string) =>
dispatch(setEmailConfirmed(verified, email)),
[dispatch],
);
};
export const useSetOrganizationId = () => {
const dispatch = useDispatch();
return useCallback(
(organizationId: string) => dispatch(setOrganizationId(organizationId)),
[dispatch],
);
};
export const useSetAuthToken = () => {
const dispatch = useDispatch();
return useCallback(
(authToken: string) => dispatch(setAuthToken(authToken)),
[dispatch],
);
};
export const useSetTenantId = () => {
const dispatch = useDispatch();
return useCallback(
(tenantId: string) => dispatch(setAuthTenantId(tenantId)),
[dispatch],
);
};
export const useSetAuthUserId = () => {
const dispatch = useDispatch();
return useCallback(
(userId: string) => dispatch(setAuthUserId(userId)),
[dispatch],
);
};
export const useSetLocale = () => {
const dispatch = useDispatch();
return useCallback(
(locale: string) => dispatch(setLocale(locale)),
[dispatch], [dispatch],
); );
}; };

View File

@@ -4,7 +4,27 @@ import t from '@/store/types';
export const setLogin = () => ({ type: t.LOGIN_SUCCESS }); export const setLogin = () => ({ type: t.LOGIN_SUCCESS });
export const setLogout = () => ({ type: t.LOGOUT }); export const setLogout = () => ({ type: t.LOGOUT });
export const setStoreReset = () => ({ type: t.RESET }); export const setStoreReset = () => ({ type: t.RESET });
export const setEmailConfirmed = (verified?: boolean) => ({ export const setEmailConfirmed = (verified?: boolean, email?: string) => ({
type: t.SET_EMAIL_VERIFIED, type: t.SET_EMAIL_VERIFIED,
action: { verified }, action: { verified, email },
});
export const setOrganizationId = (organizationId: string) => ({
type: t.SET_ORGANIZATIOIN_ID,
action: { organizationId },
});
export const setAuthToken = (token: string) => ({
type: t.SET_AUTH_TOKEN,
action: { token },
});
export const setAuthTenantId = (tenantId: string) => ({
type: t.SET_TENANT_ID,
action: { tenantId },
});
export const setAuthUserId = (userId: string) => ({
type: t.SET_USER_ID,
action: { userId },
});
export const setLocale = (locale: string) => ({
type: t.SET_LOCALE,
action: { locale },
}); });

View File

@@ -9,12 +9,13 @@ import t from '@/store/types';
// Read stored data in cookies and merge it with the initial state. // Read stored data in cookies and merge it with the initial state.
const initialState = { const initialState = {
token: getCookie('token'), token: getCookie('token') || null,
organizationId: getCookie('organization_id'), organizationId: getCookie('organization_id') || null,
tenantId: getCookie('tenant_id'), tenantId: getCookie('tenant_id') || null,
userId: getCookie('authenticated_user_id'), userId: getCookie('authenticated_user_id') || null,
locale: getCookie('locale'), locale: getCookie('locale') || 'en',
verified: true, // Let's be optimistic and assume the user's email is confirmed. verified: true, // Let's be optimistic and assume the user's email is confirmed.
verifyEmail: null,
errors: [], errors: [],
}; };
@@ -36,11 +37,35 @@ const reducerInstance = createReducer(initialState, {
[t.SET_EMAIL_VERIFIED]: ( [t.SET_EMAIL_VERIFIED]: (
state, state,
payload: PayloadAction<{ verified?: boolean }>, payload: PayloadAction<{ verified?: boolean; email?: string }>,
) => { ) => {
state.verified = !isUndefined(payload.action.verified) state.verified = !isUndefined(payload.action.verified)
? payload.action.verified ? payload.action.verified
: true; : true;
state.verifyEmail = payload.action.email || null;
if (state.verified) {
state.verifyEmail = null;
}
},
[t.SET_AUTH_TOKEN]: (state, payload: PayloadAction<{ token: string }>) => {
state.token = payload.action.token;
},
[t.SET_ORGANIZATIOIN_ID]: (
state,
payload: PayloadAction<{ organizationId: string }>,
) => {
state.organizationId = payload.action.organizationId;
},
[t.SET_TENANT_ID]: (state, payload: PayloadAction<{ tenantId: string }>) => {
state.tenantId = payload.action.tenantId;
},
[t.SET_USER_ID]: (state, payload: PayloadAction<{ userId: string }>) => {
state.userId = payload.action.userId;
}, },
[t.RESET]: (state) => { [t.RESET]: (state) => {

View File

@@ -7,5 +7,10 @@ export default {
LOGOUT: 'LOGOUT', LOGOUT: 'LOGOUT',
LOGIN_CLEAR_ERRORS: 'LOGIN_CLEAR_ERRORS', LOGIN_CLEAR_ERRORS: 'LOGIN_CLEAR_ERRORS',
RESET: 'RESET', RESET: 'RESET',
SET_EMAIL_VERIFIED: 'SET_EMAIL_VERIFIED' SET_EMAIL_VERIFIED: 'SET_EMAIL_VERIFIED',
SET_AUTH_TOKEN: 'SET_AUTH_TOKEN',
SET_ORGANIZATIOIN_ID: 'SET_ORGANIZATIOIN_ID',
SET_TENANT_ID: 'SET_TENANT_ID',
SET_USER_ID: 'SET_USER_ID',
SET_LOCALE: 'SET_LOCALE',
}; };