diff --git a/src/apis/SenderIdentity.ts b/src/apis/SenderIdentity.ts index f9c1e9f..add844b 100644 --- a/src/apis/SenderIdentity.ts +++ b/src/apis/SenderIdentity.ts @@ -3,8 +3,15 @@ import api from '@/utils/api'; export const getSenderIdentities = async () => { const response = await api.get('/api/sender-identity'); const data = await response.data; - { - console.log(data, '-->checking sender-identity data'); - } return data; }; + +export const createSenderIndentity = async (data: any) => { + try { + const response = await api.post('/api/sender-identity', data); + const dataResponse = await response.data; + return dataResponse; + } catch (error: any) { + throw error; + } +}; diff --git a/src/app/(auth)/sender-identity/create/page.tsx b/src/app/(auth)/sender-identity/create/page.tsx new file mode 100644 index 0000000..89a5d38 --- /dev/null +++ b/src/app/(auth)/sender-identity/create/page.tsx @@ -0,0 +1,43 @@ +'use client'; + +import { AtSymbolIcon } from '@heroicons/react/24/outline'; +import { useFormik } from 'formik'; +import { createSenderIndentity } from '@/apis/SenderIdentity'; +import { toast } from 'react-toastify'; +import { useRouter } from 'next/navigation'; +import { senderIdentityValidation } from '@/validations/senderIdentity'; +import SenderIdentity from '@/components/Forms/SenderIdentity'; + +const Page = () => { + const router = useRouter(); + const onSubmit = async (values: any) => { + try { + await createSenderIndentity(values); + toast.success('Sender Identity created successfully'); + router.back(); + } catch (error: any) { + toast.error(error.response.data.message); + } + }; + const formik = useFormik({ + initialValues: { + email: '', + name: '', + }, + onSubmit: onSubmit, + validationSchema: senderIdentityValidation, + }); + return ( +
+
+

+ + Create Sender Identity +

+
+ +
+ ); +}; + +export default Page; diff --git a/src/app/(auth)/sender-identity/page.tsx b/src/app/(auth)/sender-identity/page.tsx index 9475c56..9230573 100644 --- a/src/app/(auth)/sender-identity/page.tsx +++ b/src/app/(auth)/sender-identity/page.tsx @@ -8,6 +8,7 @@ import { AtSymbolIcon } from '@heroicons/react/24/outline'; import { SenderIdentity, TableData } from '@/utils/types'; import { PencilSquareIcon, TrashIcon } from '@heroicons/react/24/solid'; import { useEffect, useState } from 'react'; +import Link from 'next/link'; const Page = () => { const [senderIdentities, setSenderIdentities] = useState< @@ -75,9 +76,12 @@ const Page = () => { )}
- +
diff --git a/src/components/Forms/SenderIdentity.tsx b/src/components/Forms/SenderIdentity.tsx new file mode 100644 index 0000000..67b1d3a --- /dev/null +++ b/src/components/Forms/SenderIdentity.tsx @@ -0,0 +1,40 @@ +import Input from '@/components/Input'; +import Button from '@/components/Button'; + +const SenderIdentity = ({ + formik, + btnName, +}: { + formik: any; + btnName: string; +}) => { + return ( + <> + +
+ + +
+ + + + ); +}; + +export default SenderIdentity; diff --git a/src/validations/senderIdentity.ts b/src/validations/senderIdentity.ts new file mode 100644 index 0000000..5e4d269 --- /dev/null +++ b/src/validations/senderIdentity.ts @@ -0,0 +1,6 @@ +import * as yup from 'yup'; + +export const senderIdentityValidation = yup.object({ + name: yup.string().trim().required('Name is required'), + email: yup.string().required('Email is required'), +});