quick fix #42
This commit is contained in:
@@ -53,6 +53,9 @@
|
|||||||
"Ilmoittautuminen sulkeutuu":
|
"Ilmoittautuminen sulkeutuu":
|
||||||
"Signup closes at",
|
"Signup closes at",
|
||||||
|
|
||||||
|
"Ilmoittautuminen onnistui!":
|
||||||
|
"Signup successful!",
|
||||||
|
|
||||||
"Ilmoittauminen on umpeutunut!":
|
"Ilmoittauminen on umpeutunut!":
|
||||||
"Signup has been closed!",
|
"Signup has been closed!",
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from "react";
|
import React, { useState } from "react";
|
||||||
import { NextPage, GetStaticProps, GetStaticPaths } from "next";
|
import { NextPage, GetStaticProps, GetStaticPaths } from "next";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
@@ -25,6 +25,8 @@ const SignUpPage: NextPage<InitialProps> = ({ initialForm }) => {
|
|||||||
const id = String(initialForm?.id ?? "");
|
const id = String(initialForm?.id ?? "");
|
||||||
const URL = `${FORM_URL}${id}/`;
|
const URL = `${FORM_URL}${id}/`;
|
||||||
const { data: signupForm, error } = useSWR<SignupForm>(URL, (url) => axios.get(url).then((res) => res.data), { fallbackData: initialForm });
|
const { data: signupForm, error } = useSWR<SignupForm>(URL, (url) => axios.get(url).then((res) => res.data), { fallbackData: initialForm });
|
||||||
|
const [isSending, setIsSending] = useState(false);
|
||||||
|
const [formSent, setFormSent] = useState(false);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@@ -42,18 +44,26 @@ const SignUpPage: NextPage<InitialProps> = ({ initialForm }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onSubmit = async ({ formData }: ISubmitEvent<string>) => {
|
const onSubmit = async ({ formData }: ISubmitEvent<string>) => {
|
||||||
|
setIsSending(true);
|
||||||
|
|
||||||
const payload: Signup = {
|
const payload: Signup = {
|
||||||
signupForm_id: signupForm.id,
|
signupForm_id: signupForm.id,
|
||||||
answer: formData,
|
answer: formData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (isSending === true) {
|
||||||
|
toast.error("Sign-up form already submitted! No need to spam send. 😟");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await SignupApi.createSignup(payload);
|
await SignupApi.createSignup(payload);
|
||||||
toast.success("Sign-up submitted successfully 😎");
|
toast.success("Sign-up submitted successfully 😎");
|
||||||
mutate(URL);
|
setFormSent(true);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
toast.error("Uh oh! Sign-up failed! 😟");
|
toast.error("Uh oh! Sign-up failed! 😟");
|
||||||
|
setIsSending(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -68,6 +78,7 @@ const SignUpPage: NextPage<InitialProps> = ({ initialForm }) => {
|
|||||||
formData={{}}
|
formData={{}}
|
||||||
onChange={noop}
|
onChange={noop}
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
|
formSent={formSent}
|
||||||
/>
|
/>
|
||||||
</PageWrapper>
|
</PageWrapper>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ interface SignUpPageViewProps {
|
|||||||
formData: any;
|
formData: any;
|
||||||
onChange: (e: IChangeEvent<unknown>, es?: ErrorSchema) => unknown;
|
onChange: (e: IChangeEvent<unknown>, es?: ErrorSchema) => unknown;
|
||||||
onSubmit: (e: ISubmitEvent<unknown>) => unknown;
|
onSubmit: (e: ISubmitEvent<unknown>) => unknown;
|
||||||
|
formSent: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const StyledSection = styled(TextSection)`
|
const StyledSection = styled(TextSection)`
|
||||||
@@ -59,6 +60,7 @@ const SignUpPageView: React.FC<SignUpPageViewProps> = ({
|
|||||||
formData,
|
formData,
|
||||||
onChange,
|
onChange,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
formSent,
|
||||||
}) => {
|
}) => {
|
||||||
const { i18n, t } = useTranslation();
|
const { i18n, t } = useTranslation();
|
||||||
const startDate = new Date(signUpForm?.start_time);
|
const startDate = new Date(signUpForm?.start_time);
|
||||||
@@ -136,7 +138,7 @@ const SignUpPageView: React.FC<SignUpPageViewProps> = ({
|
|||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
{form}
|
{ formSent ? <p>{`${t("Ilmoittautuminen onnistui!")}`}</p> : form }
|
||||||
</div>
|
</div>
|
||||||
{signups}
|
{signups}
|
||||||
</StyledSection>
|
</StyledSection>
|
||||||
|
|||||||
Reference in New Issue
Block a user