Skip to content

Commit

Permalink
Merge pull request #967 from Wheezy049/feat/newsletter-subcription
Browse files Browse the repository at this point in the history
update the endpoint format change from the backend
  • Loading branch information
Samadeen authored Aug 14, 2024
2 parents d24bdbf + 7209a86 commit a2fffb6
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/components/layouts/footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import { Toaster } from "~/components/ui/toaster";
import { useToast } from "~/components/ui/use-toast";

const Footer = () => {
const [values, setValues] = useState("");
const [email, setEmail] = useState("");
const [loading, setLoading] = useState(false);
const { toast } = useToast();

// handle submit
const handleSubmit = async () => {
setLoading(true);

if (values === "") {
if (email === "") {
toast({
title: "Error",
description: "Please provide your email",
Expand All @@ -38,23 +38,28 @@ const Footer = () => {
return;
}

const payload = {
email: values,
};
// const payload = {
// email: values,
// };

try {
const apiUrl = await getApiUrl();
const response = await axios.post(
`${apiUrl}/api/v1/newsletter-subscription`,
payload,
{ email },
{
headers: {
"Content-Type": "application/json",
},
},
);
toast({
title: "Success",
description: response?.data?.message,
variant: "default",
});
setLoading(false);
setValues("");
setEmail("");
} catch (error: unknown) {
if (error instanceof Error) {
toast({
Expand Down Expand Up @@ -154,8 +159,8 @@ const Footer = () => {
<Input
placeholder="Enter your email"
className="border-r-none text-md h-[46px] rounded-r-none border-r-0 border-r-transparent bg-transparent active:border-transparent"
onChange={(event) => setValues(event.target.value)}
value={values}
onChange={(event) => setEmail(event.target.value)}
value={email}
/>
<CustomButton
variant="primary"
Expand Down Expand Up @@ -207,8 +212,8 @@ const Footer = () => {
<Input
className="border-r-none h-[46px] rounded-r-none border-r-0 border-r-transparent bg-transparent active:border-transparent"
placeholder="Enter your email"
onChange={(event) => setValues(event.target.value)}
value={values}
onChange={(event) => setEmail(event.target.value)}
value={email}
/>
<CustomButton
variant="primary"
Expand Down

0 comments on commit a2fffb6

Please sign in to comment.