| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- "use client";
- import { useCallback } from "react";
- import { GET_CUSTOMER_ADDRESS } from "@/graphql";
- import {useApolloClient} from "@apollo/client/react";
- import { GetCustomerAddressVariables } from "@/types/customer/type";
- import {normalizePhoneForForm} from "@/utils/phoneNumberTools";
- export function useGetCustomerAddress() {
- const apolloClient = useApolloClient();
- const getCustomerAddress = useCallback((param:GetCustomerAddressVariables) => {
- return apolloClient.query({
- query: GET_CUSTOMER_ADDRESS,
- variables: param,
- fetchPolicy: "no-cache",
- context: {
- fetchOptions: {
- cache: 'no-store',
- },
-
- }
- }).then((res) => {
- const addressList = res.data?.getCustomerAddresses?.edges?.map((edge) => {
- const item = {...edge.node};
- item.phone = normalizePhoneForForm(edge.node.phone, edge.node.country);
- return item;
- // return {
- // cursor: edge.cursor,
- // node: item
- // };
- }) || [];
-
- return {
- data: {
- list: addressList,
- pageInfo: res.data?.pageInfo,
- totalCount: res.data?.totalCount
- },
- error: false,
- msg: ""
- };
-
- }).catch((err) => {
- return {
- data: null,
- error: true,
- msg: err.message,
- }
- });
- },[apolloClient]);
-
- return {
- getCustomerAddress
- };
- }
|