Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature:- Create Sender Identity Page #6

Open
wants to merge 9 commits into
base: feature/create-tag-page
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/apis/SenderIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
43 changes: 43 additions & 0 deletions src/app/(auth)/sender-identity/create/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className="flex flex-col">
<div className="flex justify-between">
<h2 className="mb-7 flex items-end">
<AtSymbolIcon className="h-9 w-9" />
<span className="ml-1 text-3xl">Create Sender Identity</span>
</h2>
</div>
<SenderIdentity formik={formik} btnName="Create" />
</div>
);
};

export default Page;
8 changes: 6 additions & 2 deletions src/app/(auth)/sender-identity/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down Expand Up @@ -75,9 +76,12 @@ const Page = () => {
)}
</h2>
<div>
<Button onClick={() => console.log('new campaign')}>
<Link
className="flex rounded-lg bg-indigo-700 px-4 py-2 text-white hover:bg-indigo-800"
href="/sender-identity/create"
>
Create Sender Identity
</Button>
</Link>
</div>
</div>
<Table data={tableData} />
Expand Down
40 changes: 40 additions & 0 deletions src/components/Forms/SenderIdentity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Input from '@/components/Input';
import Button from '@/components/Button';

const SenderIdentity = ({
formik,
btnName,
}: {
formik: any;
btnName: string;
}) => {
return (
<>
<form onSubmit={formik.handleSubmit}>
<div className="grid grid-cols-2 gap-2">
<Input
type="text"
name="name"
label="Name"
placeholder="Enter Name"
value={formik.values.name}
onChange={formik.handleChange}
required={formik.errors.name}
/>
<Input
type="email"
name="email"
label="Email"
placeholder="Enter Email"
value={formik.values.email}
onChange={formik.handleChange}
required={formik.errors.email}
/>
</div>
<Button type="submit">{btnName}</Button>
</form>
</>
);
};

export default SenderIdentity;
6 changes: 6 additions & 0 deletions src/validations/senderIdentity.ts
Original file line number Diff line number Diff line change
@@ -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'),
});