Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
3de18ab46f | ||
![]() |
54f509ee38 |
@@ -1,52 +0,0 @@
|
|||||||
name: release-tag
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- 'main'
|
|
||||||
jobs:
|
|
||||||
release-image:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
env:
|
|
||||||
DOCKER_ORG: groot
|
|
||||||
DOCKER_LATEST: latest
|
|
||||||
RUNNER_TOOL_CACHE: /toolcache
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v2
|
|
||||||
|
|
||||||
- name: Set up Docker BuildX
|
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
with: # replace it with your local IP
|
|
||||||
config-inline: |
|
|
||||||
[registry."git.send.nrw"]
|
|
||||||
http = true
|
|
||||||
insecure = true
|
|
||||||
|
|
||||||
- name: Login to DockerHub
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
registry: git.send.nrw # replace it with your local IP
|
|
||||||
username: ${{ secrets.DOCKER_USERNAME }}
|
|
||||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
||||||
|
|
||||||
- name: Get Meta
|
|
||||||
id: meta
|
|
||||||
run: |
|
|
||||||
echo REPO_NAME=$(echo ${GITHUB_REPOSITORY} | awk -F"/" '{print $2}') >> $GITHUB_OUTPUT
|
|
||||||
echo REPO_VERSION=$(git describe --tags --always | sed 's/^v//') >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Build and push
|
|
||||||
uses: docker/build-push-action@v4
|
|
||||||
with:
|
|
||||||
context: ./docker
|
|
||||||
file: ./docker/Dockerfile.compose
|
|
||||||
entrypoint: ./docker/compose-entrypoint.sh
|
|
||||||
platforms: |
|
|
||||||
linux/amd64
|
|
||||||
push: true
|
|
||||||
tags: | # replace it with your local IP and tags
|
|
||||||
git.send.nrw/${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ steps.meta.outputs.REPO_VERSION }}
|
|
||||||
git.send.nrw/${{ env.DOCKER_ORG }}/${{ steps.meta.outputs.REPO_NAME }}:${{ env.DOCKER_LATEST }}
|
|
@@ -1,7 +1,10 @@
|
|||||||
version: '3.9'
|
version: '3.9'
|
||||||
services:
|
services:
|
||||||
main:
|
main:
|
||||||
image: git.send.nrw/groot/automatisch:latest
|
build:
|
||||||
|
context: ./docker
|
||||||
|
dockerfile: Dockerfile.compose
|
||||||
|
entrypoint: /compose-entrypoint.sh
|
||||||
ports:
|
ports:
|
||||||
- '3000:3000'
|
- '3000:3000'
|
||||||
depends_on:
|
depends_on:
|
||||||
@@ -25,7 +28,10 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- automatisch_storage:/automatisch/storage
|
- automatisch_storage:/automatisch/storage
|
||||||
worker:
|
worker:
|
||||||
image: git.send.nrw/groot/automatisch:latest
|
build:
|
||||||
|
context: ./docker
|
||||||
|
dockerfile: Dockerfile.compose
|
||||||
|
entrypoint: /compose-entrypoint.sh
|
||||||
depends_on:
|
depends_on:
|
||||||
- main
|
- main
|
||||||
environment:
|
environment:
|
||||||
|
@@ -1,4 +1,27 @@
|
|||||||
import { generateQueue } from './queue.js';
|
import process from 'process';
|
||||||
|
import { Queue } from 'bullmq';
|
||||||
|
import redisConfig from '../config/redis.js';
|
||||||
|
import logger from '../helpers/logger.js';
|
||||||
|
|
||||||
|
const CONNECTION_REFUSED = 'ECONNREFUSED';
|
||||||
|
|
||||||
|
const redisConnection = {
|
||||||
|
connection: redisConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
const actionQueue = new Queue('action', redisConnection);
|
||||||
|
|
||||||
|
actionQueue.on('error', (error) => {
|
||||||
|
if (error.code === CONNECTION_REFUSED) {
|
||||||
|
logger.error(
|
||||||
|
'Make sure you have installed Redis and it is running.',
|
||||||
|
error
|
||||||
|
);
|
||||||
|
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error('Error happened in action queue!', error);
|
||||||
|
});
|
||||||
|
|
||||||
const actionQueue = generateQueue('action');
|
|
||||||
export default actionQueue;
|
export default actionQueue;
|
||||||
|
@@ -1,4 +1,27 @@
|
|||||||
import { generateQueue } from './queue.js';
|
import process from 'process';
|
||||||
|
import { Queue } from 'bullmq';
|
||||||
|
import redisConfig from '../config/redis.js';
|
||||||
|
import logger from '../helpers/logger.js';
|
||||||
|
|
||||||
|
const CONNECTION_REFUSED = 'ECONNREFUSED';
|
||||||
|
|
||||||
|
const redisConnection = {
|
||||||
|
connection: redisConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteUserQueue = new Queue('delete-user', redisConnection);
|
||||||
|
|
||||||
|
deleteUserQueue.on('error', (error) => {
|
||||||
|
if (error.code === CONNECTION_REFUSED) {
|
||||||
|
logger.error(
|
||||||
|
'Make sure you have installed Redis and it is running.',
|
||||||
|
error
|
||||||
|
);
|
||||||
|
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error('Error happened in delete user queue!', error);
|
||||||
|
});
|
||||||
|
|
||||||
const deleteUserQueue = generateQueue('delete-user');
|
|
||||||
export default deleteUserQueue;
|
export default deleteUserQueue;
|
||||||
|
@@ -1,4 +1,27 @@
|
|||||||
import { generateQueue } from './queue.js';
|
import process from 'process';
|
||||||
|
import { Queue } from 'bullmq';
|
||||||
|
import redisConfig from '../config/redis.js';
|
||||||
|
import logger from '../helpers/logger.js';
|
||||||
|
|
||||||
|
const CONNECTION_REFUSED = 'ECONNREFUSED';
|
||||||
|
|
||||||
|
const redisConnection = {
|
||||||
|
connection: redisConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
const emailQueue = new Queue('email', redisConnection);
|
||||||
|
|
||||||
|
emailQueue.on('error', (error) => {
|
||||||
|
if (error.code === CONNECTION_REFUSED) {
|
||||||
|
logger.error(
|
||||||
|
'Make sure you have installed Redis and it is running.',
|
||||||
|
error
|
||||||
|
);
|
||||||
|
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error('Error happened in email queue!', error);
|
||||||
|
});
|
||||||
|
|
||||||
const emailQueue = generateQueue('email');
|
|
||||||
export default emailQueue;
|
export default emailQueue;
|
||||||
|
@@ -1,4 +1,27 @@
|
|||||||
import { generateQueue } from './queue.js';
|
import process from 'process';
|
||||||
|
import { Queue } from 'bullmq';
|
||||||
|
import redisConfig from '../config/redis.js';
|
||||||
|
import logger from '../helpers/logger.js';
|
||||||
|
|
||||||
|
const CONNECTION_REFUSED = 'ECONNREFUSED';
|
||||||
|
|
||||||
|
const redisConnection = {
|
||||||
|
connection: redisConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
const flowQueue = new Queue('flow', redisConnection);
|
||||||
|
|
||||||
|
flowQueue.on('error', (error) => {
|
||||||
|
if (error.code === CONNECTION_REFUSED) {
|
||||||
|
logger.error(
|
||||||
|
'Make sure you have installed Redis and it is running.',
|
||||||
|
error
|
||||||
|
);
|
||||||
|
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error('Error happened in flow queue!', error);
|
||||||
|
});
|
||||||
|
|
||||||
const flowQueue = generateQueue('flow');
|
|
||||||
export default flowQueue;
|
export default flowQueue;
|
||||||
|
@@ -1,44 +0,0 @@
|
|||||||
import process from 'process';
|
|
||||||
import { Queue } from 'bullmq';
|
|
||||||
import redisConfig from '../config/redis.js';
|
|
||||||
import logger from '../helpers/logger.js';
|
|
||||||
|
|
||||||
const CONNECTION_REFUSED = 'ECONNREFUSED';
|
|
||||||
|
|
||||||
const redisConnection = {
|
|
||||||
connection: redisConfig,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const generateQueue = (queueName, options) => {
|
|
||||||
const queue = new Queue(queueName, redisConnection);
|
|
||||||
|
|
||||||
queue.on('error', (error) => queueOnError(error, queueName));
|
|
||||||
|
|
||||||
if (options?.runDaily) addScheduler(queueName, queue);
|
|
||||||
|
|
||||||
return queue;
|
|
||||||
};
|
|
||||||
|
|
||||||
const queueOnError = (error, queueName) => {
|
|
||||||
if (error.code === CONNECTION_REFUSED) {
|
|
||||||
const errorMessage =
|
|
||||||
'Make sure you have installed Redis and it is running.';
|
|
||||||
|
|
||||||
logger.error(errorMessage, error);
|
|
||||||
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.error(`Error happened in ${queueName} queue!`, error);
|
|
||||||
};
|
|
||||||
|
|
||||||
const addScheduler = (queueName, queue) => {
|
|
||||||
const everydayAtOneOclock = '0 1 * * *';
|
|
||||||
|
|
||||||
queue.add(queueName, null, {
|
|
||||||
jobId: queueName,
|
|
||||||
repeat: {
|
|
||||||
pattern: everydayAtOneOclock,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
@@ -1,8 +1,40 @@
|
|||||||
import { generateQueue } from './queue.js';
|
import process from 'process';
|
||||||
|
import { Queue } from 'bullmq';
|
||||||
|
import redisConfig from '../config/redis.js';
|
||||||
|
import logger from '../helpers/logger.js';
|
||||||
|
|
||||||
const removeCancelledSubscriptionsQueue = generateQueue(
|
const CONNECTION_REFUSED = 'ECONNREFUSED';
|
||||||
|
|
||||||
|
const redisConnection = {
|
||||||
|
connection: redisConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeCancelledSubscriptionsQueue = new Queue(
|
||||||
'remove-cancelled-subscriptions',
|
'remove-cancelled-subscriptions',
|
||||||
{ runDaily: true }
|
redisConnection
|
||||||
);
|
);
|
||||||
|
|
||||||
|
removeCancelledSubscriptionsQueue.on('error', (error) => {
|
||||||
|
if (error.code === CONNECTION_REFUSED) {
|
||||||
|
logger.error(
|
||||||
|
'Make sure you have installed Redis and it is running.',
|
||||||
|
error
|
||||||
|
);
|
||||||
|
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error(
|
||||||
|
'Error happened in remove cancelled subscriptions queue!',
|
||||||
|
error
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
removeCancelledSubscriptionsQueue.add('remove-cancelled-subscriptions', null, {
|
||||||
|
jobId: 'remove-cancelled-subscriptions',
|
||||||
|
repeat: {
|
||||||
|
pattern: '0 1 * * *',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export default removeCancelledSubscriptionsQueue;
|
export default removeCancelledSubscriptionsQueue;
|
||||||
|
@@ -1,4 +1,27 @@
|
|||||||
import { generateQueue } from './queue.js';
|
import process from 'process';
|
||||||
|
import { Queue } from 'bullmq';
|
||||||
|
import redisConfig from '../config/redis.js';
|
||||||
|
import logger from '../helpers/logger.js';
|
||||||
|
|
||||||
|
const CONNECTION_REFUSED = 'ECONNREFUSED';
|
||||||
|
|
||||||
|
const redisConnection = {
|
||||||
|
connection: redisConfig,
|
||||||
|
};
|
||||||
|
|
||||||
|
const triggerQueue = new Queue('trigger', redisConnection);
|
||||||
|
|
||||||
|
triggerQueue.on('error', (error) => {
|
||||||
|
if (error.code === CONNECTION_REFUSED) {
|
||||||
|
logger.error(
|
||||||
|
'Make sure you have installed Redis and it is running.',
|
||||||
|
error
|
||||||
|
);
|
||||||
|
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.error('Error happened in trigger queue!', error);
|
||||||
|
});
|
||||||
|
|
||||||
const triggerQueue = generateQueue('trigger');
|
|
||||||
export default triggerQueue;
|
export default triggerQueue;
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { BasePage } from "./base-page";
|
import { BasePage } from './base-page';
|
||||||
const { faker } = require('@faker-js/faker');
|
const { faker } = require('@faker-js/faker');
|
||||||
const { expect } = require('@playwright/test');
|
const { expect } = require('@playwright/test');
|
||||||
|
|
||||||
@@ -14,8 +14,10 @@ export class AdminSetupPage extends BasePage {
|
|||||||
this.fullNameTextField = this.page.getByTestId('fullName-text-field');
|
this.fullNameTextField = this.page.getByTestId('fullName-text-field');
|
||||||
this.emailTextField = this.page.getByTestId('email-text-field');
|
this.emailTextField = this.page.getByTestId('email-text-field');
|
||||||
this.passwordTextField = this.page.getByTestId('password-text-field');
|
this.passwordTextField = this.page.getByTestId('password-text-field');
|
||||||
this.repeatPasswordTextField = this.page.getByTestId('repeat-password-text-field');
|
this.repeatPasswordTextField = this.page.getByTestId(
|
||||||
this.createAdminButton = this.page.getByTestId('signUp-button');
|
'repeat-password-text-field'
|
||||||
|
);
|
||||||
|
this.createAdminButton = this.page.getByTestId('installation-button');
|
||||||
this.invalidFields = this.page.locator('p.Mui-error');
|
this.invalidFields = this.page.locator('p.Mui-error');
|
||||||
this.successAlert = this.page.getByTestId('success-alert');
|
this.successAlert = this.page.getByTestId('success-alert');
|
||||||
}
|
}
|
||||||
@@ -59,7 +61,10 @@ export class AdminSetupPage extends BasePage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async expectSuccessMessageToContainLoginLink() {
|
async expectSuccessMessageToContainLoginLink() {
|
||||||
await expect(await this.successAlert.locator('a')).toHaveAttribute('href', '/login');
|
await expect(await this.successAlert.locator('a')).toHaveAttribute(
|
||||||
|
'href',
|
||||||
|
'/login'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
generateUser() {
|
generateUser() {
|
||||||
@@ -69,7 +74,7 @@ export class AdminSetupPage extends BasePage {
|
|||||||
fullName: faker.person.fullName(),
|
fullName: faker.person.fullName(),
|
||||||
email: faker.internet.email(),
|
email: faker.internet.email(),
|
||||||
password: faker.internet.password(),
|
password: faker.internet.password(),
|
||||||
wronglyRepeatedPassword: faker.internet.password()
|
wronglyRepeatedPassword: faker.internet.password(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
@@ -46,7 +46,12 @@ function Form(props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<FormProvider {...methods}>
|
<FormProvider {...methods}>
|
||||||
<form onSubmit={methods.handleSubmit(onSubmit)} {...formProps}>
|
<form
|
||||||
|
onSubmit={methods.handleSubmit((data, event) =>
|
||||||
|
onSubmit?.(data, event, methods.setError),
|
||||||
|
)}
|
||||||
|
{...formProps}
|
||||||
|
>
|
||||||
{render ? render(methods) : children}
|
{render ? render(methods) : children}
|
||||||
</form>
|
</form>
|
||||||
</FormProvider>
|
</FormProvider>
|
||||||
|
@@ -2,35 +2,55 @@ import * as React from 'react';
|
|||||||
import { Link as RouterLink } from 'react-router-dom';
|
import { Link as RouterLink } from 'react-router-dom';
|
||||||
import Paper from '@mui/material/Paper';
|
import Paper from '@mui/material/Paper';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import { Alert } from '@mui/material';
|
import Alert from '@mui/material/Alert';
|
||||||
import LoadingButton from '@mui/lab/LoadingButton';
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import { yupResolver } from '@hookform/resolvers/yup';
|
import { yupResolver } from '@hookform/resolvers/yup';
|
||||||
import { enqueueSnackbar } from 'notistack';
|
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import Link from '@mui/material/Link';
|
import Link from '@mui/material/Link';
|
||||||
|
|
||||||
|
import { getGeneralErrorMessage } from 'helpers/errors';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useInstallation from 'hooks/useInstallation';
|
import useInstallation from 'hooks/useInstallation';
|
||||||
import * as URLS from 'config/urls';
|
import * as URLS from 'config/urls';
|
||||||
import Form from 'components/Form';
|
import Form from 'components/Form';
|
||||||
import TextField from 'components/TextField';
|
import TextField from 'components/TextField';
|
||||||
|
|
||||||
const validationSchema = yup.object().shape({
|
const getValidationSchema = (formatMessage) => {
|
||||||
fullName: yup.string().trim().required('installationForm.mandatoryInput'),
|
const getMandatoryInputMessage = (inputNameId) =>
|
||||||
|
formatMessage('installationForm.mandatoryInput', {
|
||||||
|
inputName: formatMessage(inputNameId),
|
||||||
|
});
|
||||||
|
|
||||||
|
return yup.object().shape({
|
||||||
|
fullName: yup
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.required(
|
||||||
|
getMandatoryInputMessage('installationForm.fullNameFieldLabel'),
|
||||||
|
),
|
||||||
email: yup
|
email: yup
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
.email('installationForm.validateEmail')
|
.required(getMandatoryInputMessage('installationForm.emailFieldLabel'))
|
||||||
.required('installationForm.mandatoryInput'),
|
.email(formatMessage('installationForm.validateEmail')),
|
||||||
password: yup.string().required('installationForm.mandatoryInput'),
|
password: yup
|
||||||
|
.string()
|
||||||
|
.required(getMandatoryInputMessage('installationForm.passwordFieldLabel'))
|
||||||
|
.min(6, formatMessage('installationForm.passwordMinLength')),
|
||||||
confirmPassword: yup
|
confirmPassword: yup
|
||||||
.string()
|
.string()
|
||||||
.required('installationForm.mandatoryInput')
|
.required(
|
||||||
.oneOf([yup.ref('password')], 'installationForm.passwordsMustMatch'),
|
getMandatoryInputMessage('installationForm.confirmPasswordFieldLabel'),
|
||||||
|
)
|
||||||
|
.oneOf(
|
||||||
|
[yup.ref('password')],
|
||||||
|
formatMessage('installationForm.passwordsMustMatch'),
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const initialValues = {
|
const defaultValues = {
|
||||||
fullName: '',
|
fullName: '',
|
||||||
email: '',
|
email: '',
|
||||||
password: '',
|
password: '',
|
||||||
@@ -39,7 +59,7 @@ const initialValues = {
|
|||||||
|
|
||||||
function InstallationForm() {
|
function InstallationForm() {
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const install = useInstallation();
|
const { mutateAsync: install, isSuccess, isPending } = useInstallation();
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
const handleOnRedirect = () => {
|
const handleOnRedirect = () => {
|
||||||
@@ -48,21 +68,38 @@ function InstallationForm() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (values) => {
|
const handleSubmit = async ({ fullName, email, password }, e, setError) => {
|
||||||
const { fullName, email, password } = values;
|
|
||||||
try {
|
try {
|
||||||
await install.mutateAsync({
|
await install({
|
||||||
fullName,
|
fullName,
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
enqueueSnackbar(
|
const errors = error?.response?.data?.errors;
|
||||||
error?.message || formatMessage('installationForm.error'),
|
if (errors) {
|
||||||
{
|
const fieldNames = Object.keys(defaultValues);
|
||||||
variant: 'error',
|
Object.entries(errors).forEach(([fieldName, fieldErrors]) => {
|
||||||
},
|
if (fieldNames.includes(fieldName) && Array.isArray(fieldErrors)) {
|
||||||
);
|
setError(fieldName, {
|
||||||
|
type: 'fieldRequestError',
|
||||||
|
message: fieldErrors.join(', '),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const generalError = getGeneralErrorMessage({
|
||||||
|
error,
|
||||||
|
fallbackMessage: formatMessage('installationForm.error'),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (generalError) {
|
||||||
|
setError('root.general', {
|
||||||
|
type: 'requestError',
|
||||||
|
message: generalError,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,11 +119,13 @@ function InstallationForm() {
|
|||||||
{formatMessage('installationForm.title')}
|
{formatMessage('installationForm.title')}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Form
|
<Form
|
||||||
defaultValues={initialValues}
|
automaticValidation={false}
|
||||||
|
noValidate
|
||||||
|
defaultValues={defaultValues}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
resolver={yupResolver(validationSchema)}
|
resolver={yupResolver(getValidationSchema(formatMessage))}
|
||||||
mode="onChange"
|
mode="onChange"
|
||||||
render={({ formState: { errors, touchedFields } }) => (
|
render={({ formState: { errors } }) => (
|
||||||
<>
|
<>
|
||||||
<TextField
|
<TextField
|
||||||
label={formatMessage('installationForm.fullNameFieldLabel')}
|
label={formatMessage('installationForm.fullNameFieldLabel')}
|
||||||
@@ -95,19 +134,12 @@ function InstallationForm() {
|
|||||||
margin="dense"
|
margin="dense"
|
||||||
autoComplete="fullName"
|
autoComplete="fullName"
|
||||||
data-test="fullName-text-field"
|
data-test="fullName-text-field"
|
||||||
error={touchedFields.fullName && !!errors?.fullName}
|
error={!!errors?.fullName}
|
||||||
helperText={
|
helperText={errors?.fullName?.message}
|
||||||
touchedFields.fullName && errors?.fullName?.message
|
|
||||||
? formatMessage(errors?.fullName?.message, {
|
|
||||||
inputName: formatMessage(
|
|
||||||
'installationForm.fullNameFieldLabel',
|
|
||||||
),
|
|
||||||
})
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
required
|
required
|
||||||
readOnly={install.isSuccess}
|
readOnly={isSuccess}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
label={formatMessage('installationForm.emailFieldLabel')}
|
label={formatMessage('installationForm.emailFieldLabel')}
|
||||||
name="email"
|
name="email"
|
||||||
@@ -115,19 +147,12 @@ function InstallationForm() {
|
|||||||
margin="dense"
|
margin="dense"
|
||||||
autoComplete="email"
|
autoComplete="email"
|
||||||
data-test="email-text-field"
|
data-test="email-text-field"
|
||||||
error={touchedFields.email && !!errors?.email}
|
error={!!errors?.email}
|
||||||
helperText={
|
helperText={errors?.email?.message}
|
||||||
touchedFields.email && errors?.email?.message
|
|
||||||
? formatMessage(errors?.email?.message, {
|
|
||||||
inputName: formatMessage(
|
|
||||||
'installationForm.emailFieldLabel',
|
|
||||||
),
|
|
||||||
})
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
required
|
required
|
||||||
readOnly={install.isSuccess}
|
readOnly={isSuccess}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
label={formatMessage('installationForm.passwordFieldLabel')}
|
label={formatMessage('installationForm.passwordFieldLabel')}
|
||||||
name="password"
|
name="password"
|
||||||
@@ -135,19 +160,12 @@ function InstallationForm() {
|
|||||||
margin="dense"
|
margin="dense"
|
||||||
type="password"
|
type="password"
|
||||||
data-test="password-text-field"
|
data-test="password-text-field"
|
||||||
error={touchedFields.password && !!errors?.password}
|
error={!!errors?.password}
|
||||||
helperText={
|
helperText={errors?.password?.message}
|
||||||
touchedFields.password && errors?.password?.message
|
|
||||||
? formatMessage(errors?.password?.message, {
|
|
||||||
inputName: formatMessage(
|
|
||||||
'installationForm.passwordFieldLabel',
|
|
||||||
),
|
|
||||||
})
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
required
|
required
|
||||||
readOnly={install.isSuccess}
|
readOnly={isSuccess}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
label={formatMessage(
|
label={formatMessage(
|
||||||
'installationForm.confirmPasswordFieldLabel',
|
'installationForm.confirmPasswordFieldLabel',
|
||||||
@@ -157,38 +175,24 @@ function InstallationForm() {
|
|||||||
margin="dense"
|
margin="dense"
|
||||||
type="password"
|
type="password"
|
||||||
data-test="repeat-password-text-field"
|
data-test="repeat-password-text-field"
|
||||||
error={touchedFields.confirmPassword && !!errors?.confirmPassword}
|
error={!!errors?.confirmPassword}
|
||||||
helperText={
|
helperText={errors?.confirmPassword?.message}
|
||||||
touchedFields.confirmPassword &&
|
|
||||||
errors?.confirmPassword?.message
|
|
||||||
? formatMessage(errors?.confirmPassword?.message, {
|
|
||||||
inputName: formatMessage(
|
|
||||||
'installationForm.confirmPasswordFieldLabel',
|
|
||||||
),
|
|
||||||
})
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
required
|
required
|
||||||
readOnly={install.isSuccess}
|
readOnly={isSuccess}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<LoadingButton
|
{errors?.root?.general && (
|
||||||
type="submit"
|
<Alert data-test="error-alert" severity="error" sx={{ mt: 2 }}>
|
||||||
variant="contained"
|
{errors.root.general.message}
|
||||||
color="primary"
|
</Alert>
|
||||||
sx={{ boxShadow: 2, mt: 3 }}
|
|
||||||
loading={install.isPending}
|
|
||||||
disabled={install.isSuccess}
|
|
||||||
fullWidth
|
|
||||||
data-test="signUp-button"
|
|
||||||
>
|
|
||||||
{formatMessage('installationForm.submit')}
|
|
||||||
</LoadingButton>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
/>
|
|
||||||
{install.isSuccess && (
|
{isSuccess && (
|
||||||
<Alert data-test="success-alert" severity="success" sx={{ mt: 3 }}>
|
<Alert
|
||||||
|
data-test="success-alert"
|
||||||
|
severity="success"
|
||||||
|
sx={{ mt: 2 }}
|
||||||
|
>
|
||||||
{formatMessage('installationForm.success', {
|
{formatMessage('installationForm.success', {
|
||||||
link: (str) => (
|
link: (str) => (
|
||||||
<Link
|
<Link
|
||||||
@@ -203,6 +207,21 @@ function InstallationForm() {
|
|||||||
})}
|
})}
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
)}
|
||||||
|
<LoadingButton
|
||||||
|
type="submit"
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
sx={{ boxShadow: 2, mt: 2 }}
|
||||||
|
loading={isPending}
|
||||||
|
disabled={isSuccess}
|
||||||
|
fullWidth
|
||||||
|
data-test="installation-button"
|
||||||
|
>
|
||||||
|
{formatMessage('installationForm.submit')}
|
||||||
|
</LoadingButton>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</Paper>
|
</Paper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -3,33 +3,52 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
import Paper from '@mui/material/Paper';
|
import Paper from '@mui/material/Paper';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import LoadingButton from '@mui/lab/LoadingButton';
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
|
import Alert from '@mui/material/Alert';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import { yupResolver } from '@hookform/resolvers/yup';
|
import { yupResolver } from '@hookform/resolvers/yup';
|
||||||
|
|
||||||
|
import { getGeneralErrorMessage } from 'helpers/errors';
|
||||||
import useAuthentication from 'hooks/useAuthentication';
|
import useAuthentication from 'hooks/useAuthentication';
|
||||||
import * as URLS from 'config/urls';
|
import * as URLS from 'config/urls';
|
||||||
import Form from 'components/Form';
|
import Form from 'components/Form';
|
||||||
import TextField from 'components/TextField';
|
import TextField from 'components/TextField';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
import useCreateAccessToken from 'hooks/useCreateAccessToken';
|
import useCreateAccessToken from 'hooks/useCreateAccessToken';
|
||||||
import useEnqueueSnackbar from 'hooks/useEnqueueSnackbar';
|
|
||||||
import useRegisterUser from 'hooks/useRegisterUser';
|
import useRegisterUser from 'hooks/useRegisterUser';
|
||||||
|
|
||||||
const validationSchema = yup.object().shape({
|
const getValidationSchema = (formatMessage) => {
|
||||||
fullName: yup.string().trim().required('signupForm.mandatoryInput'),
|
const getMandatoryInputMessage = (inputNameId) =>
|
||||||
|
formatMessage('signupForm.mandatoryInput', {
|
||||||
|
inputName: formatMessage(inputNameId),
|
||||||
|
});
|
||||||
|
|
||||||
|
return yup.object().shape({
|
||||||
|
fullName: yup
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.required(getMandatoryInputMessage('signupForm.fullNameFieldLabel')),
|
||||||
email: yup
|
email: yup
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
.email('signupForm.validateEmail')
|
.required(getMandatoryInputMessage('signupForm.emailFieldLabel'))
|
||||||
.required('signupForm.mandatoryInput'),
|
.email(formatMessage('signupForm.validateEmail')),
|
||||||
password: yup.string().required('signupForm.mandatoryInput'),
|
password: yup
|
||||||
|
.string()
|
||||||
|
.required(getMandatoryInputMessage('signupForm.passwordFieldLabel'))
|
||||||
|
.min(6, formatMessage('signupForm.passwordMinLength')),
|
||||||
confirmPassword: yup
|
confirmPassword: yup
|
||||||
.string()
|
.string()
|
||||||
.required('signupForm.mandatoryInput')
|
.required(
|
||||||
.oneOf([yup.ref('password')], 'signupForm.passwordsMustMatch'),
|
getMandatoryInputMessage('signupForm.confirmPasswordFieldLabel'),
|
||||||
|
)
|
||||||
|
.oneOf(
|
||||||
|
[yup.ref('password')],
|
||||||
|
formatMessage('signupForm.passwordsMustMatch'),
|
||||||
|
),
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const initialValues = {
|
const defaultValues = {
|
||||||
fullName: '',
|
fullName: '',
|
||||||
email: '',
|
email: '',
|
||||||
password: '',
|
password: '',
|
||||||
@@ -40,7 +59,6 @@ function SignUpForm() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const authentication = useAuthentication();
|
const authentication = useAuthentication();
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const enqueueSnackbar = useEnqueueSnackbar();
|
|
||||||
const { mutateAsync: registerUser, isPending: isRegisterUserPending } =
|
const { mutateAsync: registerUser, isPending: isRegisterUserPending } =
|
||||||
useRegisterUser();
|
useRegisterUser();
|
||||||
const { mutateAsync: createAccessToken, isPending: loginLoading } =
|
const { mutateAsync: createAccessToken, isPending: loginLoading } =
|
||||||
@@ -52,7 +70,7 @@ function SignUpForm() {
|
|||||||
}
|
}
|
||||||
}, [authentication.isAuthenticated]);
|
}, [authentication.isAuthenticated]);
|
||||||
|
|
||||||
const handleSubmit = async (values) => {
|
const handleSubmit = async (values, e, setError) => {
|
||||||
try {
|
try {
|
||||||
const { fullName, email, password } = values;
|
const { fullName, email, password } = values;
|
||||||
await registerUser({
|
await registerUser({
|
||||||
@@ -67,25 +85,28 @@ function SignUpForm() {
|
|||||||
const { token } = data;
|
const { token } = data;
|
||||||
authentication.updateToken(token);
|
authentication.updateToken(token);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errors = error?.response?.data?.errors
|
const errors = error?.response?.data?.errors;
|
||||||
? Object.values(error.response.data.errors)
|
if (errors) {
|
||||||
: [];
|
const fieldNames = Object.keys(defaultValues);
|
||||||
|
Object.entries(errors).forEach(([fieldName, fieldErrors]) => {
|
||||||
if (errors.length) {
|
if (fieldNames.includes(fieldName) && Array.isArray(fieldErrors)) {
|
||||||
for (const [error] of errors) {
|
setError(fieldName, {
|
||||||
enqueueSnackbar(error, {
|
type: 'fieldRequestError',
|
||||||
variant: 'error',
|
message: fieldErrors.join(', '),
|
||||||
SnackbarProps: {
|
|
||||||
'data-test': 'snackbar-sign-up-error',
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
});
|
||||||
enqueueSnackbar(error?.message || formatMessage('signupForm.error'), {
|
}
|
||||||
variant: 'error',
|
|
||||||
SnackbarProps: {
|
const generalError = getGeneralErrorMessage({
|
||||||
'data-test': 'snackbar-sign-up-error',
|
error,
|
||||||
},
|
fallbackMessage: formatMessage('signupForm.error'),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (generalError) {
|
||||||
|
setError('root.general', {
|
||||||
|
type: 'requestError',
|
||||||
|
message: generalError,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,11 +129,13 @@ function SignUpForm() {
|
|||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Form
|
<Form
|
||||||
defaultValues={initialValues}
|
automaticValidation={false}
|
||||||
|
noValidate
|
||||||
|
defaultValues={defaultValues}
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
resolver={yupResolver(validationSchema)}
|
resolver={yupResolver(getValidationSchema(formatMessage))}
|
||||||
mode="onChange"
|
mode="onChange"
|
||||||
render={({ formState: { errors, touchedFields } }) => (
|
render={({ formState: { errors } }) => (
|
||||||
<>
|
<>
|
||||||
<TextField
|
<TextField
|
||||||
label={formatMessage('signupForm.fullNameFieldLabel')}
|
label={formatMessage('signupForm.fullNameFieldLabel')}
|
||||||
@@ -121,14 +144,9 @@ function SignUpForm() {
|
|||||||
margin="dense"
|
margin="dense"
|
||||||
autoComplete="fullName"
|
autoComplete="fullName"
|
||||||
data-test="fullName-text-field"
|
data-test="fullName-text-field"
|
||||||
error={touchedFields.fullName && !!errors?.fullName}
|
error={!!errors?.fullName}
|
||||||
helperText={
|
helperText={errors?.fullName?.message}
|
||||||
touchedFields.fullName && errors?.fullName?.message
|
required
|
||||||
? formatMessage(errors?.fullName?.message, {
|
|
||||||
inputName: formatMessage('signupForm.fullNameFieldLabel'),
|
|
||||||
})
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
@@ -138,14 +156,9 @@ function SignUpForm() {
|
|||||||
margin="dense"
|
margin="dense"
|
||||||
autoComplete="email"
|
autoComplete="email"
|
||||||
data-test="email-text-field"
|
data-test="email-text-field"
|
||||||
error={touchedFields.email && !!errors?.email}
|
error={!!errors?.email}
|
||||||
helperText={
|
helperText={errors?.email?.message}
|
||||||
touchedFields.email && errors?.email?.message
|
required
|
||||||
? formatMessage(errors?.email?.message, {
|
|
||||||
inputName: formatMessage('signupForm.emailFieldLabel'),
|
|
||||||
})
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
@@ -154,14 +167,9 @@ function SignUpForm() {
|
|||||||
fullWidth
|
fullWidth
|
||||||
margin="dense"
|
margin="dense"
|
||||||
type="password"
|
type="password"
|
||||||
error={touchedFields.password && !!errors?.password}
|
error={!!errors?.password}
|
||||||
helperText={
|
helperText={errors?.password?.message}
|
||||||
touchedFields.password && errors?.password?.message
|
required
|
||||||
? formatMessage(errors?.password?.message, {
|
|
||||||
inputName: formatMessage('signupForm.passwordFieldLabel'),
|
|
||||||
})
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
@@ -170,19 +178,21 @@ function SignUpForm() {
|
|||||||
fullWidth
|
fullWidth
|
||||||
margin="dense"
|
margin="dense"
|
||||||
type="password"
|
type="password"
|
||||||
error={touchedFields.confirmPassword && !!errors?.confirmPassword}
|
error={!!errors?.confirmPassword}
|
||||||
helperText={
|
helperText={errors?.confirmPassword?.message}
|
||||||
touchedFields.confirmPassword &&
|
required
|
||||||
errors?.confirmPassword?.message
|
|
||||||
? formatMessage(errors?.confirmPassword?.message, {
|
|
||||||
inputName: formatMessage(
|
|
||||||
'signupForm.confirmPasswordFieldLabel',
|
|
||||||
),
|
|
||||||
})
|
|
||||||
: ''
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{errors?.root?.general && (
|
||||||
|
<Alert
|
||||||
|
data-test="alert-sign-up-error"
|
||||||
|
severity="error"
|
||||||
|
sx={{ mt: 2 }}
|
||||||
|
>
|
||||||
|
{errors.root.general.message}
|
||||||
|
</Alert>
|
||||||
|
)}
|
||||||
|
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
18
packages/web/src/helpers/errors.js
Normal file
18
packages/web/src/helpers/errors.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
// Helpers to extract errors received from the API
|
||||||
|
|
||||||
|
export const getGeneralErrorMessage = ({ error, fallbackMessage }) => {
|
||||||
|
if (!error) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const errors = error?.response?.data?.errors;
|
||||||
|
const generalError = errors?.general;
|
||||||
|
|
||||||
|
if (generalError && Array.isArray(generalError)) {
|
||||||
|
return generalError.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!errors) {
|
||||||
|
return error?.message || fallbackMessage;
|
||||||
|
}
|
||||||
|
};
|
@@ -138,6 +138,7 @@
|
|||||||
"installationForm.submit": "Create admin",
|
"installationForm.submit": "Create admin",
|
||||||
"installationForm.validateEmail": "Email must be valid.",
|
"installationForm.validateEmail": "Email must be valid.",
|
||||||
"installationForm.passwordsMustMatch": "Passwords must match.",
|
"installationForm.passwordsMustMatch": "Passwords must match.",
|
||||||
|
"installationForm.passwordMinLength": "Password must be at least 6 characters long.",
|
||||||
"installationForm.mandatoryInput": "{inputName} is required.",
|
"installationForm.mandatoryInput": "{inputName} is required.",
|
||||||
"installationForm.success": "The admin account has been created, and thus, the installation has been completed. You can now log in <link>here</link>.",
|
"installationForm.success": "The admin account has been created, and thus, the installation has been completed. You can now log in <link>here</link>.",
|
||||||
"installationForm.error": "Something went wrong. Please try again.",
|
"installationForm.error": "Something went wrong. Please try again.",
|
||||||
@@ -149,6 +150,7 @@
|
|||||||
"signupForm.submit": "Sign up",
|
"signupForm.submit": "Sign up",
|
||||||
"signupForm.validateEmail": "Email must be valid.",
|
"signupForm.validateEmail": "Email must be valid.",
|
||||||
"signupForm.passwordsMustMatch": "Passwords must match.",
|
"signupForm.passwordsMustMatch": "Passwords must match.",
|
||||||
|
"signupForm.passwordMinLength": "Password must be at least 6 characters long.",
|
||||||
"signupForm.mandatoryInput": "{inputName} is required.",
|
"signupForm.mandatoryInput": "{inputName} is required.",
|
||||||
"signupForm.error": "Something went wrong. Please try again.",
|
"signupForm.error": "Something went wrong. Please try again.",
|
||||||
"loginForm.title": "Login",
|
"loginForm.title": "Login",
|
||||||
|
Reference in New Issue
Block a user