From 0e93d8447b5f427b6f1767dd64e9d4eb34b91290 Mon Sep 17 00:00:00 2001 From: Vasile Chindris Date: Tue, 5 Mar 2024 16:18:44 +0200 Subject: [PATCH] chore(SLB-218): code style, typescript fixes and success messages after submit --- apps/website/src/templates/contact.tsx | 2 +- apps/website/src/utils/drupal-executor.ts | 8 +- .../schema/src/operations/ContactRequest.gql | 6 +- .../src/components/Molecules/ContactForm.tsx | 206 ++++++++++-------- packages/ui/src/utils/operation.ts | 48 ++-- tests/schema/specs/contact.spec.ts | 32 ++- 6 files changed, 167 insertions(+), 135 deletions(-) diff --git a/apps/website/src/templates/contact.tsx b/apps/website/src/templates/contact.tsx index 77f8e781b..09dbe50e5 100644 --- a/apps/website/src/templates/contact.tsx +++ b/apps/website/src/templates/contact.tsx @@ -2,5 +2,5 @@ import { Contact } from '@custom/ui/routes/Contact'; import React from 'react'; export default function ContentHubPage() { - return + return ; } diff --git a/apps/website/src/utils/drupal-executor.ts b/apps/website/src/utils/drupal-executor.ts index 0dfc1ad6d..e90218389 100644 --- a/apps/website/src/utils/drupal-executor.ts +++ b/apps/website/src/utils/drupal-executor.ts @@ -15,18 +15,18 @@ export function drupalExecutor(endpoint: string, forward: boolean = true) { method: 'POST', credentials: 'include', body: JSON.stringify({ - 'queryId': id, - 'variables': variables.variables, + queryId: id, + variables: variables.variables, }), headers: forward ? { 'SLB-Forwarded-Proto': window.location.protocol.slice(0, -1), 'SLB-Forwarded-Host': window.location.hostname, 'SLB-Forwarded-Port': window.location.port, - "Content-Type": "application/json", + 'Content-Type': 'application/json', } : { - "Content-Type": "application/json", + 'Content-Type': 'application/json', }, }) ).json(); diff --git a/packages/schema/src/operations/ContactRequest.gql b/packages/schema/src/operations/ContactRequest.gql index 8cf6c09e6..878063452 100644 --- a/packages/schema/src/operations/ContactRequest.gql +++ b/packages/schema/src/operations/ContactRequest.gql @@ -1,6 +1,4 @@ -mutation ContactRequest ( - $contact: ContactInput -){ +mutation ContactRequest($contact: ContactInput) { createContact(contact: $contact) { errors { key @@ -14,4 +12,4 @@ mutation ContactRequest ( subject } } -} \ No newline at end of file +} diff --git a/packages/ui/src/components/Molecules/ContactForm.tsx b/packages/ui/src/components/Molecules/ContactForm.tsx index e5e8f52d6..be4c3eeda 100644 --- a/packages/ui/src/components/Molecules/ContactForm.tsx +++ b/packages/ui/src/components/Molecules/ContactForm.tsx @@ -20,99 +20,121 @@ export function ContactForm() { const { register, handleSubmit } = useForm(); const { data, trigger, isMutating } = useMutation(ContactRequestMutation); - const errorMessages = (!isMutating && data && data.createContact?.errors && data.createContact.errors.length > 0 ) ? - data.createContact.errors.map(error => { - return error?.message || ''; - }) - : - null; + const errorMessages = + !isMutating && + data && + data.createContact?.errors && + data.createContact.errors.length > 0 + ? data.createContact.errors.map((error) => { + return error?.message || ''; + }) + : null; + const successMessages = + !isMutating && data && data.createContact?.contact + ? [ + intl.formatMessage({ + defaultMessage: 'The contact has been submitted.', + id: 'gD5ZU1', + }), + ] + : null; + return ( -
- { errorMessages ? : null} -
{ - // @todo: fix this - // @ts-ignore - trigger({ - contact: values, - }); - })} - > -
- - -
-
- - -
-
- - -
-
- -