summaryrefslogtreecommitdiff
path: root/src-migrate/modules/product-detail/stores/useProductDetail.ts
blob: eb409930ea06892ee4e9fa6d09bb382a3298fac0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { create } from 'zustand';
import { IProductVariantDetail } from '~/types/productVariant';

type State = {
  activeVariantId: number | null;
  activePrice: IProductVariantDetail['price'] | null;
  quantityInput: string;
  askAdminUrl: string;
  isApproval : boolean;
};

type Action = {
  setActive: (variant: IProductVariantDetail) => void;
  setQuantityInput: (value: string) => void;
  setAskAdminUrl: (url: string) => void;
  setIsApproval : (value : boolean) => void;
};

export const useProductDetail = create<State & Action>((set, get) => ({
  activeVariantId: null,
  activePrice: null,
  quantityInput: '1',
  askAdminUrl: '',
  isApproval : false,
  setActive: (variant) => {
    set({ activeVariantId: variant?.id, activePrice: variant?.price });
  },
  setQuantityInput: (value: string) => {
    set({ quantityInput: value });
  },
  setAskAdminUrl: (url: string) => {
    set({ askAdminUrl: url });
  },
  setIsApproval : (value : boolean) => {
    set({ isApproval : value })
  }
}));