Skip to content

Commit

Permalink
refactor(core): update submit create account errors message
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-alexsaiannyi committed Nov 16, 2024
1 parent 1971781 commit 5748c49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { client } from '~/client';
import { graphql, VariablesOf } from '~/client/graphql';
import { parseRegisterCustomerFormData } from '~/components/form-fields/shared/parse-fields';

import { createErrorsList } from '../../../account/(tabs)/_components/utils';

const RegisterCustomerMutation = graphql(`
mutation RegisterCustomer($input: RegisterCustomerInput!, $reCaptchaV2: ReCaptchaV2Input) {
customer {
Expand Down Expand Up @@ -84,7 +86,7 @@ export const registerCustomer = async ({ formData, reCaptchaToken }: RegisterCus

return {
status: 'error',
error: result.errors.map((error) => error.message).join('\n'),
error: createErrorsList(result.errors),
};
} catch (error) {
// eslint-disable-next-line no-console
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export const RegisterCustomerForm = ({
return (
<>
{formStatus && (
<Message className="mb-8" variant={formStatus.status}>
<Message className="mb-8 whitespace-pre-line" variant={formStatus.status}>
<p>{formStatus.message}</p>
</Message>
)}
Expand Down
15 changes: 15 additions & 0 deletions core/app/[locale]/(default)/account/(tabs)/_components/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
interface GenericError {
[p: string]: string | string[];
message: string;
}

export const createErrorsList = (submitErrors: GenericError[]) =>
submitErrors
.map((error) => {
if (submitErrors.length > 1) {
return `\u2022 ${error.message}`;
}

return error.message;
})
.join('\n');

0 comments on commit 5748c49

Please sign in to comment.