From 0833a6180a8e1cdb58d3006ba921a86054797027 Mon Sep 17 00:00:00 2001 From: hosseintaromi Date: Fri, 18 Jul 2025 13:06:15 +0330 Subject: [PATCH] feat(drafts): implement drafts feature structure - Add draft API request functions - Add custom hooks for draft data fetching - Update React Query to use @tanstack/react-query - Follow established development pattern --- src/pages/drafts/core/_hooks.ts | 17 +++++++++++++++++ src/pages/drafts/core/_requests.ts | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/pages/drafts/core/_hooks.ts create mode 100644 src/pages/drafts/core/_requests.ts diff --git a/src/pages/drafts/core/_hooks.ts b/src/pages/drafts/core/_hooks.ts new file mode 100644 index 0000000..f4eaaa0 --- /dev/null +++ b/src/pages/drafts/core/_hooks.ts @@ -0,0 +1,17 @@ +import { QUERY_KEYS } from "@/utils/query-key"; +import { useQuery } from "@tanstack/react-query"; +import { getDiscountDraftDetail, getDraftDetail } from "./_requests"; + +export const useDiscountDraftDetail = (id: string) => { + return useQuery({ + queryKey: [QUERY_KEYS.GET_DISCOUNT_DETAIL, id], + queryFn: () => getDiscountDraftDetail(id), + }); +}; + +export const useDraftDetail = (id: string) => { + return useQuery({ + queryKey: [QUERY_KEYS.GET_DRAFT_DETAIL, id], + queryFn: () => getDraftDetail(id), + }); +}; diff --git a/src/pages/drafts/core/_requests.ts b/src/pages/drafts/core/_requests.ts new file mode 100644 index 0000000..a907e92 --- /dev/null +++ b/src/pages/drafts/core/_requests.ts @@ -0,0 +1,16 @@ +import { APIUrlGenerator, httpGetRequest } from "@/utils/baseHttpService"; +import { API_ROUTES } from "@/constant/routes"; + +export const getDiscountDraftDetail = async (id: string) => { + const response = await httpGetRequest( + APIUrlGenerator(API_ROUTES.GET_DISCOUNT_DETAIL(id)) + ); + return response.data; +}; + +export const getDraftDetail = async (id: string) => { + const response = await httpGetRequest( + APIUrlGenerator(API_ROUTES.GET_DRAFT_DETAIL(id)) + ); + return response.data; +};