Created a discount system related to the user's e-mail address and applied to the packages
This commit is contained in:
22
src/hooks/useDiscounts.tsx
Normal file
22
src/hooks/useDiscounts.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Discount } from "@/interfaces/paypal";
|
||||
import { Code, Group, User } from "@/interfaces/user";
|
||||
import axios from "axios";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export default function useDiscounts(creator?: string) {
|
||||
const [discounts, setDiscounts] = useState<Discount[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [isError, setIsError] = useState(false);
|
||||
|
||||
const getData = () => {
|
||||
setIsLoading(true);
|
||||
axios
|
||||
.get<Discount[]>("/api/discounts")
|
||||
.then((response) => setDiscounts(response.data))
|
||||
.finally(() => setIsLoading(false));
|
||||
};
|
||||
|
||||
useEffect(getData, [creator]);
|
||||
|
||||
return { discounts, isLoading, isError, reload: getData };
|
||||
}
|
||||
Reference in New Issue
Block a user