Commit e316d359 authored by tom's avatar tom

re-submit new application

parent 59431115
...@@ -65,7 +65,10 @@ const VerifiedAddresses = () => { ...@@ -65,7 +65,10 @@ const VerifiedAddresses = () => {
return { submissions: [ newItem ] }; return { submissions: [ newItem ] };
} }
const submissions = prevData.submissions.map((item) => item.id === newItem.id ? newItem : item); const isExisting = prevData.submissions.some((item) => item.id === newItem.id);
const submissions = isExisting ?
prevData.submissions.map((item) => item.id === newItem.id ? newItem : item) :
[ newItem, ...prevData.submissions ];
return { submissions }; return { submissions };
}); });
}, [ queryClient ]); }, [ queryClient ]);
......
...@@ -7,6 +7,7 @@ import type { Fields } from './types'; ...@@ -7,6 +7,7 @@ import type { Fields } from './types';
import type { TokenInfoApplication } from 'types/api/account'; import type { TokenInfoApplication } from 'types/api/account';
import appConfig from 'configs/app/config'; import appConfig from 'configs/app/config';
import type { ResourceError } from 'lib/api/resources';
import useApiFetch from 'lib/api/useApiFetch'; import useApiFetch from 'lib/api/useApiFetch';
import useApiQuery from 'lib/api/useApiQuery'; import useApiQuery from 'lib/api/useApiQuery';
import useToast from 'lib/hooks/useToast'; import useToast from 'lib/hooks/useToast';
...@@ -56,10 +57,12 @@ const TokenInfoForm = ({ address, application, onSubmit }: Props) => { ...@@ -56,10 +57,12 @@ const TokenInfoForm = ({ address, application, onSubmit }: Props) => {
const onFormSubmit: SubmitHandler<Fields> = React.useCallback(async(data) => { const onFormSubmit: SubmitHandler<Fields> = React.useCallback(async(data) => {
try { try {
const submission = prepareRequestBody(data); const submission = prepareRequestBody(data);
const isNewApplication = !application?.id || [ 'REJECTED', 'APPROVED' ].includes(application.status);
const result = await apiFetch<'token_info_applications', TokenInfoApplication, { message: string }>('token_info_applications', { const result = await apiFetch<'token_info_applications', TokenInfoApplication, { message: string }>('token_info_applications', {
pathParams: { chainId: appConfig.network.id, id: application?.id }, pathParams: { chainId: appConfig.network.id, id: !isNewApplication ? application.id : undefined },
fetchParams: { fetchParams: {
method: application?.id ? 'PUT' : 'POST', method: isNewApplication ? 'POST' : 'PUT',
body: { submission }, body: { submission },
}, },
}); });
...@@ -73,13 +76,13 @@ const TokenInfoForm = ({ address, application, onSubmit }: Props) => { ...@@ -73,13 +76,13 @@ const TokenInfoForm = ({ address, application, onSubmit }: Props) => {
toast({ toast({
position: 'top-right', position: 'top-right',
title: 'Error', title: 'Error',
description: (error as Error)?.message || 'Something went wrong. Try again later.', description: (error as ResourceError<{ message: string }>)?.payload?.message || 'Something went wrong. Try again later.',
status: 'error', status: 'error',
variant: 'subtle', variant: 'subtle',
isClosable: true, isClosable: true,
}); });
} }
}, [ apiFetch, application?.id, onSubmit, toast ]); }, [ apiFetch, application?.id, application?.status, onSubmit, toast ]);
useUpdateEffect(() => { useUpdateEffect(() => {
if (formState.submitCount > 0 && !formState.isValid) { if (formState.submitCount > 0 && !formState.isValid) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment