diff options
Diffstat (limited to 'src-migrate/modules')
7 files changed, 352 insertions, 10 deletions
diff --git a/src-migrate/modules/cart/components/CartSummaryMobile.tsx b/src-migrate/modules/cart/components/CartSummaryMobile.tsx index d9f72e0e..02258204 100644 --- a/src-migrate/modules/cart/components/CartSummaryMobile.tsx +++ b/src-migrate/modules/cart/components/CartSummaryMobile.tsx @@ -29,6 +29,7 @@ const CartSummaryMobile = ({ isLoaded = false, }: Props) => { const [showPopup, setShowPopup] = useState(false); + const PPN : number = process.env.NEXT_PUBLIC_PPN ? parseFloat(process.env.NEXT_PUBLIC_PPN) : 0; return ( <> <BottomPopup @@ -63,7 +64,7 @@ const CartSummaryMobile = ({ </Skeleton> <Skeleton isLoaded={isLoaded} className={style.line}> - <span className={style.label}>Tax 11%</span> + <span className={style.label}>Tax {((PPN - 1) * 100).toFixed(0)}%</span> <span className={style.value}>Rp {formatCurrency(tax || 0)}</span> </Skeleton> diff --git a/src-migrate/modules/cart/components/Summary.tsx b/src-migrate/modules/cart/components/Summary.tsx index 2e55c8df..0af5ab18 100644 --- a/src-migrate/modules/cart/components/Summary.tsx +++ b/src-migrate/modules/cart/components/Summary.tsx @@ -25,6 +25,7 @@ const CartSummary = ({ grandTotal, isLoaded = false, }: Props) => { + const PPN : number = process.env.NEXT_PUBLIC_PPN ? parseFloat(process.env.NEXT_PUBLIC_PPN) : 0; return ( <> <div className='text-h-sm font-medium'>Ringkasan Pesanan</div> @@ -50,7 +51,7 @@ const CartSummary = ({ </Skeleton> <Skeleton isLoaded={isLoaded} className={style.line}> - <span className={style.label}>Tax 11%</span> + <span className={style.label}>Tax {((PPN - 1) * 100).toFixed(0)}%</span> <span className={style.value}>Rp {formatCurrency(tax || 0)}</span> </Skeleton> diff --git a/src-migrate/modules/cart/stores/useCartStore.ts b/src-migrate/modules/cart/stores/useCartStore.ts index c2ebf50f..e7d2cdd3 100644 --- a/src-migrate/modules/cart/stores/useCartStore.ts +++ b/src-migrate/modules/cart/stores/useCartStore.ts @@ -43,17 +43,20 @@ export const useCartStore = create<State & Action>((set, get) => ({ updateCartItem: (updatedCart) => { const cart = get().cart; if (!cart) return; - + set({ cart: updatedCart }); const summary = computeSummary(updatedCart); set({ summary }); }, - + })); const computeSummary = (cart: CartProps) => { let subtotal = 0; let discount = 0; + + const PPN: number = process.env.NEXT_PUBLIC_PPN ? parseFloat(process.env.NEXT_PUBLIC_PPN) : 0; + for (const item of cart?.products) { if (!item.selected) continue; @@ -67,8 +70,9 @@ const computeSummary = (cart: CartProps) => { discount += price - item.price.price_discount * item.quantity; } let total = subtotal - discount; - let tax = Math.round(total * 0.11); - let grandTotal = total + tax; + let grandTotal = total * PPN; + let tax = grandTotal - total; + // let grandTotal = total + tax; - return { subtotal, discount, total, tax, grandTotal }; + return { subtotal, discount, total, grandTotal, tax }; };
\ No newline at end of file diff --git a/src-migrate/modules/product-card/components/ProductCard.tsx b/src-migrate/modules/product-card/components/ProductCard.tsx index a439cdc8..8d3b55fb 100644 --- a/src-migrate/modules/product-card/components/ProductCard.tsx +++ b/src-migrate/modules/product-card/components/ProductCard.tsx @@ -16,6 +16,7 @@ type Props = { layout?: 'vertical' | 'horizontal'; }; +const PPN : number = process.env.NEXT_PUBLIC_PPN ? parseFloat(process.env.NEXT_PUBLIC_PPN) : 0; const ProductCard = ({ product, layout = 'vertical' }: Props) => { const utmSource = useUtmSource(); const { isDesktop, isMobile } = useDevice(); @@ -127,7 +128,7 @@ const ProductCard = ({ product, layout = 'vertical' }: Props) => { <div className={style['price-inc']}> Inc PPN: Rp{' '} - {formatCurrency(Math.round(product.lowest_price.price * 1.11))} + {formatCurrency(Math.round(product.lowest_price.price * PPN))} </div> <div className='h-1' /> diff --git a/src-migrate/modules/product-detail/components/PriceAction.tsx b/src-migrate/modules/product-detail/components/PriceAction.tsx index 0b27b1b3..9348bbfb 100644 --- a/src-migrate/modules/product-detail/components/PriceAction.tsx +++ b/src-migrate/modules/product-detail/components/PriceAction.tsx @@ -17,6 +17,7 @@ type Props = { product: IProductDetail; }; +const PPN : number = process.env.NEXT_PUBLIC_PPN ? parseFloat(process.env.NEXT_PUBLIC_PPN) : 0; const PriceAction = ({ product }: Props) => { const { activePrice, @@ -101,7 +102,7 @@ const PriceAction = ({ product }: Props) => { <div className='h-1' /> <div className={style['secondary-text']}> Termasuk PPN: Rp{' '} - {formatCurrency(Math.round(activePrice.price_discount * 1.11))} + {formatCurrency(Math.round(activePrice.price_discount * PPN))} </div> </> )} diff --git a/src-migrate/modules/register/index.tsx b/src-migrate/modules/register/index.tsx index 347f5c80..39f4771c 100644 --- a/src-migrate/modules/register/index.tsx +++ b/src-migrate/modules/register/index.tsx @@ -163,7 +163,7 @@ const Register = () => { )} </div> <section className='mt-2'> - <FormCaptcha /> + {/* <FormCaptcha /> */} <TermCondition /> <Button type='submit' diff --git a/src-migrate/modules/register/stores/usePengajuanTempoStore.ts b/src-migrate/modules/register/stores/usePengajuanTempoStore.ts new file mode 100644 index 00000000..1e086c06 --- /dev/null +++ b/src-migrate/modules/register/stores/usePengajuanTempoStore.ts @@ -0,0 +1,334 @@ +import { create } from 'zustand'; +import { + TempoProps, + TempoPropsKontakPerson, + TempoPropsPengiriman, + TempoPropsSupplier, + TempoPropsDokumen, +} from '~/types/tempo'; +import { + TempoSchema, + TempoSchemaKontakPerson, + TempoSchemaPengiriman, + TempoSchemaSupplier, + TempoSchemaDokumen, +} from '~/validations/tempo'; +import { boolean, ZodError } from 'zod'; + +type State = { + form: TempoProps; + errors: { + [key in keyof TempoProps]?: string; + }; + isCheckedTNC: boolean; + isOpenTNC: boolean; + isValidCaptcha: boolean; +}; + +type Action = { + updateForm: (name: string, value: string) => void; + updateValidCaptcha: (value: boolean) => void; + toggleCheckTNC: () => void; + openTNC: () => void; + closeTNC: () => void; + validate: () => void; + resetForm: () => void; +}; + +export const usePengajuanTempoStore = create<State & Action>((set, get) => ({ + form: { + name: '', + industryId: '', + street: '', + state: '', + city: '', + district: '', + subDistrict: '', + zip: '', + mobile: '', + bankName: '', + accountName: '', + accountNumber: '', + estimasi: '', + tempoDuration: '', + bersedia: '', + portal: '', + website: '', + categoryProduk: '', + tempoLimit: '', + }, + updateForm: (name, value) => + set((state) => ({ form: { ...state.form, [name]: value } })), + + errors: {}, + validate: () => { + try { + TempoSchema.parse(get().form); + set({ errors: {} }); + } catch (error) { + if (error instanceof ZodError) { + const errors: State['errors'] = {}; + error.errors.forEach( + (e) => (errors[e.path[0] as keyof TempoProps] = e.message) + ); + set({ errors }); + } + } + }, + + isCheckedTNC: false, + toggleCheckTNC: () => set((state) => ({ isCheckedTNC: !state.isCheckedTNC })), + + isOpenTNC: false, + openTNC: () => set(() => ({ isOpenTNC: true })), + closeTNC: () => set(() => ({ isOpenTNC: false })), + + isValidCaptcha: false, + updateValidCaptcha: (value) => set(() => ({ isValidCaptcha: value })), + + resetForm: () => + set({ + form: { + name: '', + industryId: '', + street: '', + state: '', + city: '', + district: '', + subDistrict: '', + zip: '', + mobile: '', + bankName: '', + accountName: '', + accountNumber: '', + website: '', + estimasi: '', + tempoDuration: '', + bersedia: '', + portal: '', + categoryProduk: '', + }, + }), +})); + +type StateKontakPerson = { + formKontakPerson: TempoPropsKontakPerson; + errorsKontakPerson: { + [key in keyof TempoPropsKontakPerson]?: string; + }; +}; +type ActionKontakPerson = { + updateFormKontakPerson: (name: string, value: string) => void; + + validateKontakPerson: () => void; +}; +export const usePengajuanTempoStoreKontakPerson = create< + StateKontakPerson & ActionKontakPerson +>((set, get) => ({ + formKontakPerson: { + direkturTittle: '', + direkturName: '', + direkturMobile: '', + direkturEmail: '', + purchasingTittle: '', + purchasingName: '', + purchasingEmail: '', + financeMobile: '', + financeTittle: '', + financeName: '', + financeEmail: '', + purchasingMobile: '', + }, + updateFormKontakPerson: (name, value) => + set((state) => ({ + formKontakPerson: { ...state.formKontakPerson, [name]: value }, + })), + + errorsKontakPerson: {}, + validateKontakPerson: () => { + try { + TempoSchemaKontakPerson.parse(get().formKontakPerson); + set({ errorsKontakPerson: {} }); + } catch (error) { + if (error instanceof ZodError) { + const errorsKontakPerson: StateKontakPerson['errorsKontakPerson'] = {}; + error.errors.forEach( + (e) => + (errorsKontakPerson[e.path[0] as keyof TempoPropsKontakPerson] = + e.message) + ); + set({ errorsKontakPerson }); + } + } + }, +})); + +type StatePengiriman = { + formPengiriman: TempoPropsPengiriman; + errorsPengiriman: { + [key in keyof TempoPropsPengiriman]?: string; + }; +}; +type ActionPengiriman = { + updateFormPengiriman: (name: string, value: string) => void; + + validatePengiriman: () => void; +}; +export const usePengajuanTempoStorePengiriman = create< + StatePengiriman & ActionPengiriman +>((set, get) => ({ + formPengiriman: { + PICTittle: '', + PICName: '', + streetPengiriman: '', + statePengiriman: '', + cityPengiriman: '', + districtPengiriman: '', + subDistrictPengiriman: '', + zipPengiriman: '', + invoicePicTittle: '', + invoicePic: '', + isSameAddrees: '', + isSameAddreesStreet: '', + streetInvoice: '', + stateInvoice: '', + cityInvoice: '', + districtInvoice: '', + subDistrictInvoice: '', + zipInvoice: '', + tukarInvoiceInput: '', + tukarInvoiceInputPembayaran: '', + dokumenPengiriman: '', + dokumenPengirimanInput: '', + dokumenKirimInput: '', + dokumenPengirimanInvoice: '', + }, + updateFormPengiriman: (name, value) => + set((state) => ({ + formPengiriman: { ...state.formPengiriman, [name]: value }, + })), + + errorsPengiriman: {}, + validatePengiriman: () => { + try { + TempoSchemaPengiriman.parse(get().formPengiriman); + set({ errorsPengiriman: {} }); + } catch (error) { + if (error instanceof ZodError) { + const errorsPengiriman: StatePengiriman['errorsPengiriman'] = {}; + error.errors.forEach( + (e) => + (errorsPengiriman[e.path[0] as keyof TempoPropsPengiriman] = + e.message) + ); + set({ errorsPengiriman }); + } + } + }, +})); +type StateDokumen = { + formDokumen: TempoPropsDokumen; + errorsDokumen: { + [key in keyof TempoPropsDokumen]?: string; + }; +}; +type ActionDokumen = { + updateFormDokumen: ( + name: string, + fileName: string, + fileFormat: string, + value: string + ) => void; + + validateDokumen: () => void; + getJumlahDokumenDiisi: () => void; +}; +export const usePengajuanTempoStoreDokumen = create< + StateDokumen & ActionDokumen +>((set, get) => ({ + formDokumen: { + dokumenNib: { name: '', format: '', base64: '' }, + dokumenNpwp: { name: '', format: '', base64: '' }, + dokumenSppkp: { name: '', format: '', base64: '' }, + dokumenSiup: { name: '', format: '', base64: '' }, + dokumenTdp: { name: '', format: '', base64: '' }, + dokumenSkdp: { name: '', format: '', base64: '' }, + dokumenSkt: { name: '', format: '', base64: '' }, + dokumenAktaPerubahan: { name: '', format: '', base64: '' }, + dokumenKtpDirut: { name: '', format: '', base64: '' }, + dokumenAktaPendirian: { name: '', format: '', base64: '' }, + dokumenLaporanKeuangan: { name: '', format: '', base64: '' }, + dokumenFotoKantor: { name: '', format: '', base64: '' }, + dokumenTempatBekerja: { name: '', format: '', base64: '' }, + }, + + // Memperbarui dokumen dengan name, format, dan base64 + updateFormDokumen: (name, fileName, fileFormat, value) => + set((state) => ({ + formDokumen: { + ...state.formDokumen, + [name]: { + name: fileName, + format: fileFormat, + base64: value, + }, + }, + })), + + errorsDokumen: {}, + validateDokumen: () => { + try { + TempoSchemaDokumen.parse(get().formDokumen); + set({ errorsDokumen: {} }); + } catch (error) { + if (error instanceof ZodError) { + const errorsDokumen: StateDokumen['errorsDokumen'] = {}; + error.errors.forEach( + (e) => + (errorsDokumen[e.path[0] as keyof TempoPropsDokumen] = e.message) + ); + set({ errorsDokumen }); + } + } + }, + + getJumlahDokumenDiisi: () => { + const formDokumen = get().formDokumen; + // Menghitung jumlah field yang base64 tidak kosong + const jumlahTerisi = Object.values(formDokumen).filter( + (dokumen) => dokumen.base64 !== '' + ).length; + return jumlahTerisi; + }, +})); + +type StateSupplier = { + hasSavedata: boolean; + formSupplier: []; + errorsSupplier: { + [key in keyof TempoPropsSupplier]?: string; + }; +}; +type ActionSupplier = { + updateFormSupplier: (data: []) => void; + updateHasSave: (data: boolean) => void; + validateSupplier: () => void; +}; +export const usePengajuanTempoStoreSupplier = create< + StateSupplier & ActionSupplier +>((set, get) => ({ + formSupplier: [], + hasSavedata: true, + updateFormSupplier: (data) => { + set(() => ({ + formSupplier: data, + })); + }, + updateHasSave: (data) => { + set(() => ({ + hasSavedata: data, + })); + }, + errorsSupplier: {}, + validateSupplier: () => {}, +})); |
