index.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use client";
  2. import { CartCheckoutPageSkeleton } from "@/components/common/skeleton/CheckoutSkeleton";
  3. import { useQuery } from "@apollo/client/react";
  4. import ShippingMethod from "./ShippingMethod";
  5. import { FC } from "react";
  6. import { SelectedShippingRateType, GetCheckoutShippingRatesData } from "@/types/checkout/type";
  7. import { GET_CHECKOUT_SHIPPING_RATES } from "@/graphql";
  8. import { getCartToken } from "@/utils/getCartToken";
  9. const Shipping: FC<{
  10. selectedShippingRate?: SelectedShippingRateType;
  11. currentStep?: string;
  12. }> = ({ selectedShippingRate, currentStep }) => {
  13. const token = getCartToken();
  14. const { data, loading: isLoading } = useQuery<GetCheckoutShippingRatesData>(GET_CHECKOUT_SHIPPING_RATES, {
  15. variables: { token: token || "" },
  16. skip: !token,
  17. fetchPolicy: "cache-first",
  18. nextFetchPolicy: "cache-first",
  19. });
  20. if (isLoading && !data) {
  21. return <CartCheckoutPageSkeleton />;
  22. }
  23. return (
  24. <ShippingMethod
  25. shippingMethod={data?.collectionShippingRates}
  26. selectedShippingRate={selectedShippingRate}
  27. methodDesc={selectedShippingRate?.methodDescription}
  28. currentStep={currentStep}
  29. />
  30. );
  31. };
  32. export default Shipping;