From 914634c9d664e12330c8b142c32c666873c99d1e Mon Sep 17 00:00:00 2001 From: barshathakuri Date: Fri, 6 Dec 2024 14:30:33 +0545 Subject: [PATCH] Error message fixes --- README.md | 3 +++ src/views/MySubscriptions/index.tsx | 2 +- src/views/NewSubscriptionModal/index.tsx | 26 +++++++++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e43815cf..422d95da 100644 --- a/README.md +++ b/README.md @@ -71,5 +71,8 @@ docker-compose up └── index.tsx (Defines root layout and requests fetched for DomainContext) ``` +## IFRC Alert Hub backend +The backend that serves the frontend application is maintained in a separate [repository](https://github.com/IFRCGo/alert-hub-backend). + ## External facing API Here is the documentation for [Alert Hub GraphQL Client Usage Guide](./APIDOCS.md) diff --git a/src/views/MySubscriptions/index.tsx b/src/views/MySubscriptions/index.tsx index 65ed4eab..9f0fcaa3 100644 --- a/src/views/MySubscriptions/index.tsx +++ b/src/views/MySubscriptions/index.tsx @@ -209,7 +209,7 @@ export function Component() { return; } if (response.ok) { - if (response.result) { + if (response.result?.isActive === true) { alert.show( strings.subscriptionUnarchived, { variant: 'success' }, diff --git a/src/views/NewSubscriptionModal/index.tsx b/src/views/NewSubscriptionModal/index.tsx index 4203dce2..4b13e7dc 100644 --- a/src/views/NewSubscriptionModal/index.tsx +++ b/src/views/NewSubscriptionModal/index.tsx @@ -40,6 +40,7 @@ import { FilteredAdminListQueryVariables, UpdateSubscriptionMutation, UpdateSubscriptionMutationVariables, + UserAlertSubscriptionEmailFrequencyEnum, UserAlertSubscriptionInput, } from '#generated/types/graphql'; import useAlert from '#hooks/useAlert'; @@ -111,6 +112,7 @@ mutation CreateUserAlertSubscription( data: $data, ) { ok + errors result { id name @@ -240,6 +242,7 @@ const formSchema: FormSchema = { }, notifyByEmail: { required: true, + defaultValue: false, }, emailFrequency: { required: !!value?.notifyByEmail, @@ -277,8 +280,9 @@ function NewSubscriptionModal(props: Props) { filterAlertCountry: subscription?.filterAlertCountry, filterAlertAdmin1s: subscription?.filterAlertAdmin1s ?? [], - notifyByEmail: subscription?.notifyByEmail ?? false, - emailFrequency: subscription?.emailFrequency ?? undefined, + notifyByEmail: subscription?.notifyByEmail, + emailFrequency: subscription?.emailFrequency + ?? UserAlertSubscriptionEmailFrequencyEnum.Monthly, }), [subscription]); const { @@ -318,10 +322,11 @@ function NewSubscriptionModal(props: Props) { onSuccess(); } } else { - alert.show( - strings.newSubscriptionLimitExceeded, - { variant: 'danger' }, - ); + const errorMessages = response?.errors + ?.map((error: { messages: string; }) => error.messages) + .filter((message: string) => message) + .join(', '); + alert.show(errorMessages, { variant: 'danger' }); } }, onError: () => { @@ -353,10 +358,11 @@ function NewSubscriptionModal(props: Props) { onSuccess(); } } else { - alert.show( - strings.newSubscriptionLimitExceeded, - { variant: 'danger' }, - ); + const errorMessages = response?.errors + ?.map((error: { messages: string; }) => error.messages) + .filter((message: string) => message) + .join(', '); + alert.show(errorMessages, { variant: 'danger' }); } }, onError: () => {