diff --git a/src/api/backend.ts b/src/api/backend.ts index d6700f0..e0a09f0 100644 --- a/src/api/backend.ts +++ b/src/api/backend.ts @@ -11,6 +11,7 @@ export enum APIPath { FEED = "/feed/:id", JOBADS = "/jobads/:id", SIGNUPS = "/signup/:id", + SIGNUPS_DELETE = "/signup/:id/delete", SIGNUPS_EDIT = "/signup/:id/edit", SIGNUP_FORMS = "/signupForm/:id", SIGNUP_FORMS_EMAIL = "/signupForm/:id/sendemail", diff --git a/src/api/signupApi.ts b/src/api/signupApi.ts index 467ca23..eff01cd 100644 --- a/src/api/signupApi.ts +++ b/src/api/signupApi.ts @@ -78,6 +78,15 @@ class SignupApi { } }; + static userDeleteSignup = async (id: number, uuid: string): Promise => { + try { + await deleteBackendAPI<{ message: "OK" }>({ path: APIPath.SIGNUPS_DELETE, urlParams: { id }, queryParams: { uuid } }); + } catch (err) { + console.error(err); + throw err; + } + }; + static getForm = async (id: number, auth = false): Promise => { try { return await getBackendAPI({ diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 5c0ee99..e4a8d4f 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -3,7 +3,7 @@ import styled from "styled-components"; import colors from "@theme/colors"; interface ButtonProps { - onClick: () => void; + onClick: (event?: React.MouseEvent) => void; buttonStyle: "hero" | "filled" | "filter" | "bordered"; selected?: boolean; } diff --git a/src/pages/signup/edit/[id]/[uuid].tsx b/src/pages/signup/edit/[id]/[uuid].tsx index 88a4d93..a14a1ad 100644 --- a/src/pages/signup/edit/[id]/[uuid].tsx +++ b/src/pages/signup/edit/[id]/[uuid].tsx @@ -67,6 +67,16 @@ const EditSignUpPage: NextPage = () => { } }; + const onDelete = async () => { + try { + await SignupApi.userDeleteSignup(Number(signupId), uuid); + toast.success("Sign-up deleted successfully 😎"); + } catch (error) { + console.error(error); + toast.error("Uh oh! Deleting sign-up failed! 😟"); + } + }; + return ( { formData={formData} onChange={noop} onSubmit={onSubmit} + onDelete={onDelete} /> ); diff --git a/src/views/SignUpPage/SignUpPageView.tsx b/src/views/SignUpPage/SignUpPageView.tsx index a97b3f1..4280d19 100644 --- a/src/views/SignUpPage/SignUpPageView.tsx +++ b/src/views/SignUpPage/SignUpPageView.tsx @@ -6,7 +6,7 @@ import { import { SignupForm } from "@models/Signup"; import Checkboxes from "@components/Widgets/Checkbox/Checkboxes"; import RadioButtonWidget from "@components/Widgets/RadioButton/RadioButtonWidget"; -import { TextSection, ChangeLanguageButton } from "@components/index"; +import { TextSection, ChangeLanguageButton, Button } from "@components/index"; import colors from "@theme/colors"; import FormWrapper from "@views/common/FormWrapper"; import Loader from "@components/Loader"; @@ -23,6 +23,7 @@ interface SignUpPageViewProps { formData: any; onChange: (e: IChangeEvent, es?: ErrorSchema) => unknown; onSubmit: (e: ISubmitEvent) => unknown; + onDelete: () => void; } const StyledSection = styled(TextSection)` @@ -59,6 +60,7 @@ const SignUpPageView: React.FC = ({ formData, onChange, onSubmit, + onDelete, }) => { const { i18n, t } = useTranslation(); const startDate = new Date(signUpForm?.start_time); @@ -127,6 +129,14 @@ const SignUpPageView: React.FC = ({ signups = renderList(); } + const deleteButton = ( + + ); + return ( <> @@ -137,6 +147,7 @@ const SignUpPageView: React.FC = ({
{form} + {deleteButton}
{signups}