Skip to content

Commit

Permalink
Update contacts.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
VLGrigoryan authored Sep 12, 2024
1 parent 14d8035 commit 6f1713d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/pages/contacts/contacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ const contactFormReducer = (state: ContactFormState, action: ContactFormAction)
}
};

const getSubmitButtonText = (formSuccessfullySent: boolean, isSubmitting: boolean) => {
if (formSuccessfullySent) {
return 'Отправлено';
} else if (isSubmitting) {
return 'Отправляется';
}

return 'Отправить';
};

const Contacts: NextPage = () => {
const [contactFormState, dispatch] = useReducer(contactFormReducer, initialContactFormState);
const [formSuccessfullySent, setFormSuccessfullySent] = useState(false);
Expand Down Expand Up @@ -154,7 +164,7 @@ const Contacts: NextPage = () => {

const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
setIsSubmitting(true);
setIsSubmitting(true);

const data = {
author_name: name.value,
Expand All @@ -166,7 +176,7 @@ const Contacts: NextPage = () => {
await fetcher('/feedback/questions/', {
method: 'POST',
headers: {
'Content-type': 'application/json',
'Content-type': 'application/json'
},
body: JSON.stringify(data),
});
Expand Down Expand Up @@ -256,11 +266,11 @@ const Contacts: NextPage = () => {
)}
iconPosition="right"
border="full"
disabled={!canSubmit || isSubmitting}
disabled={!canSubmit || isSubmitting}
upperCase
fullWidth
>
{formSuccessfullySent ? 'Отправлено' : isSubmitting ? 'Отправляется' : 'Отправить'}
{getSubmitButtonText(formSuccessfullySent, isSubmitting)}
</Button>
</Form.Actions>
<Form.Disclaimer className={styles.container}>
Expand Down

0 comments on commit 6f1713d

Please sign in to comment.