diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-17 15:16:23 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-11-17 15:16:23 +0700 |
| commit | 07819844d5ef7e323fd956eacfedecb2f4f4bb80 (patch) | |
| tree | d83ba8c6ff7f47f568889ff8371ee9d9918ed166 /src/modules/result/components/ImportModal.tsx | |
| parent | 10ce1ad59969576244ba786d7d17da2da3fe6f61 (diff) | |
Update result feature
Diffstat (limited to 'src/modules/result/components/ImportModal.tsx')
| -rw-r--r-- | src/modules/result/components/ImportModal.tsx | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/modules/result/components/ImportModal.tsx b/src/modules/result/components/ImportModal.tsx index 85e4a97..1551ab2 100644 --- a/src/modules/result/components/ImportModal.tsx +++ b/src/modules/result/components/ImportModal.tsx @@ -1,7 +1,9 @@ import toast from '@/common/libs/toast' +import { useResultStore } from '@/common/stores/useResultStore' import { Button, Modal, ModalBody, ModalContent, ModalHeader } from '@nextui-org/react' import { useMutation } from '@tanstack/react-query' -import React, { ChangeEvent, FormEvent, useState } from 'react' +import { AlertTriangleIcon } from 'lucide-react' +import React, { ChangeEvent, FormEvent, useMemo, useState } from 'react' type Props = { modal: { @@ -12,6 +14,11 @@ type Props = { const ImportModal = ({ modal }: Props) => { const [file, setFile] = useState<File>() + const { companies, filter } = useResultStore() + + const selectedCompany = useMemo(() => { + return companies.find((c) => c.value == filter.company) + }, [companies, filter.company]) const handleFileChange = (e: ChangeEvent<HTMLInputElement>) => { if (e.target.files) setFile(e.target.files[0]) @@ -21,7 +28,7 @@ const ImportModal = ({ modal }: Props) => { mutationKey: ['import-product'], mutationFn: async () => { if (!file) return - return await fetch('/api/product/import', { + return await fetch(`/api/product/import?companyId=${filter.company}`, { method: 'POST', body: file, headers: { 'content-type': file.type, 'content-length': `${file.size}` } @@ -52,6 +59,15 @@ const ImportModal = ({ modal }: Props) => { <Button type='submit' color='primary' className='mt-4 w-full' isDisabled={!file || importMutation.isPending}> {importMutation.isPending ? 'Loading...' : 'Submit'} </Button> + + <div className='text-xs p-4 bg-danger-600 text-neutral-50 rounded-medium mt-4 flex items-center gap-x-4'> + <div> + <AlertTriangleIcon size={28} /> + </div> + <span> + Hati-hati aksi ini akan menghapus semua data produk dan hasil stock opname di perusahaan {selectedCompany?.label} + </span> + </div> </form> </ModalBody> </ModalContent> |
