From 07819844d5ef7e323fd956eacfedecb2f4f4bb80 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 17 Nov 2023 15:16:23 +0700 Subject: Update result feature --- src/modules/login/index.tsx | 4 +- src/modules/login/login.module.css | 2 +- src/modules/profile-card/index.tsx | 10 ++- src/modules/result/components/DetailRow.tsx | 38 ++++++----- src/modules/result/components/Filter.tsx | 70 ++++++++++++--------- src/modules/result/components/ImportModal.tsx | 20 +++++- src/modules/result/components/MoreMenu.tsx | 4 +- src/modules/result/components/ProductModal.tsx | 6 +- src/modules/result/components/Table.tsx | 83 +++++++++++++++++++++---- src/modules/result/components/filter.module.css | 2 +- src/modules/result/components/table.module.css | 4 -- src/modules/result/index.tsx | 2 +- src/modules/stock-opname/index.tsx | 27 ++++---- 13 files changed, 181 insertions(+), 91 deletions(-) (limited to 'src/modules') diff --git a/src/modules/login/index.tsx b/src/modules/login/index.tsx index 7247af4..e2b3675 100644 --- a/src/modules/login/index.tsx +++ b/src/modules/login/index.tsx @@ -7,11 +7,11 @@ const Login = () => {

Stock Opname

- +

Masuk terlebih dahulu untuk melanjutkan

- +
) diff --git a/src/modules/login/login.module.css b/src/modules/login/login.module.css index 99575d5..384dc09 100644 --- a/src/modules/login/login.module.css +++ b/src/modules/login/login.module.css @@ -7,7 +7,7 @@ } .title { - @apply text-2xl text-blue-600 font-semibold; + @apply text-3xl text-primary-500 font-bold; } .subtitle { diff --git a/src/modules/profile-card/index.tsx b/src/modules/profile-card/index.tsx index 08c4478..881561d 100644 --- a/src/modules/profile-card/index.tsx +++ b/src/modules/profile-card/index.tsx @@ -1,13 +1,11 @@ -import { Credential } from "@/common/types/auth" import { Avatar, AvatarIcon, Card, CardBody } from '@nextui-org/react'; -import { teamAliases } from '@/common/constants/team'; +import { TEAM_ALIASES } from '@/common/constants/team'; import styles from "./profile-card.module.css" import Dropdown from './components/Dropdown'; -import { cookies } from 'next/headers'; +import getServerCredential from '@/common/libs/getServerCredential'; const ProfileCard = () => { - const credentialStr = cookies().get('credential')?.value - const credential: Credential | null = credentialStr ? JSON.parse(credentialStr) : null + const credential = getServerCredential() return credential && ( @@ -21,7 +19,7 @@ const ProfileCard = () => { · - Tim {teamAliases[credential.team].name} + Tim {TEAM_ALIASES[credential.team].name} diff --git a/src/modules/result/components/DetailRow.tsx b/src/modules/result/components/DetailRow.tsx index 99ccb01..29cf984 100644 --- a/src/modules/result/components/DetailRow.tsx +++ b/src/modules/result/components/DetailRow.tsx @@ -7,6 +7,7 @@ import styles from './table.module.css' import { CornerDownRightIcon } from 'lucide-react'; import { User } from '@prisma/client'; import clsxm from '@/common/libs/clsxm'; +import getClientCredential from '@/common/libs/getClientCredential'; const DetailRow = ({ productId }: { productId: number }) => { const { filter } = useResultStore() @@ -26,7 +27,7 @@ const DetailRow = ({ productId }: { productId: number }) => { if (detailLocation.isLoading) { return ( - +
@@ -53,6 +54,9 @@ const DetailRow = ({ productId }: { productId: number }) => { + + + @@ -64,18 +68,24 @@ const DetailRow = ({ productId }: { productId: number }) => { ) } -const QuantityColumn = ({ data }: { data: { quantity?: number | undefined, user?: User } }) => ( -
- {typeof data?.quantity !== 'number' && '-'} - {data.quantity !== null && ( - <> - {data.quantity} -
- {data.user?.name} -
- - )} -
-) +const QuantityColumn = ({ data }: { data: { quantity?: number | undefined, user?: User } }) => { + const credential = getClientCredential() + + if (!(credential?.team == "VERIFICATION")) return '-' + + return ( +
+ {typeof data?.quantity !== 'number' && '-'} + {data.quantity !== null && ( + <> + {data.quantity} +
+ {data.user?.name} +
+ + )} +
+ ) +} export default DetailRow \ No newline at end of file diff --git a/src/modules/result/components/Filter.tsx b/src/modules/result/components/Filter.tsx index f8bc7b5..73f346c 100644 --- a/src/modules/result/components/Filter.tsx +++ b/src/modules/result/components/Filter.tsx @@ -1,19 +1,16 @@ "use client"; import { Input, Select, SelectItem } from "@nextui-org/react" -import styles from "./filter.module.css" import { Company } from "@prisma/client" -import { useEffect, useState } from "react" +import { useEffect } from "react" import { SelectOption } from "@/common/types/select" import { useResultStore } from "@/common/stores/useResultStore"; -import { getCookie } from "cookies-next"; -import { Credential } from "@/common/types/auth"; +import getClientCredential from "@/common/libs/getClientCredential"; +import { SHOWING_SELECTIONS } from "@/common/constants/result"; const Filter = () => { - const { filter, updateFilter } = useResultStore() - const [companies, setCompanies] = useState([]) + const { filter, updateFilter, companies, setCompanies } = useResultStore() - const credentialStr = getCookie('credential') - const credential: Credential | null = credentialStr ? JSON.parse(credentialStr) : null + const credential = getClientCredential() useEffect(() => { if (credential && !filter.company) @@ -24,7 +21,7 @@ const Filter = () => { loadCompany().then((data: SelectOption[]) => { setCompanies(data) }) - }, [updateFilter]) + }, [setCompanies]) const handleInputChange = (e: React.ChangeEvent) => { const { name, value } = e.target @@ -37,26 +34,41 @@ const Filter = () => { } return ( -
- - +
+
+ +
+
+ +
+
+ +
) } 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() + const { companies, filter } = useResultStore() + + const selectedCompany = useMemo(() => { + return companies.find((c) => c.value == filter.company) + }, [companies, filter.company]) const handleFileChange = (e: ChangeEvent) => { 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) => { + +
+
+ +
+ + Hati-hati aksi ini akan menghapus semua data produk dan hasil stock opname di perusahaan {selectedCompany?.label} + +
diff --git a/src/modules/result/components/MoreMenu.tsx b/src/modules/result/components/MoreMenu.tsx index a7380f4..03c9786 100644 --- a/src/modules/result/components/MoreMenu.tsx +++ b/src/modules/result/components/MoreMenu.tsx @@ -4,12 +4,14 @@ import { MoreVerticalIcon } from 'lucide-react' import React from 'react' import ImportModal from './ImportModal'; import ProductModal from './ProductModal'; +import getClientCredential from '@/common/libs/getClientCredential'; const MoreMenu = () => { + const credential = getClientCredential() const importModal = useDisclosure(); const productModal = useDisclosure(); - return ( + return credential && credential.team == 'VERIFICATION' && ( <> diff --git a/src/modules/result/components/ProductModal.tsx b/src/modules/result/components/ProductModal.tsx index a4ef49e..001c946 100644 --- a/src/modules/result/components/ProductModal.tsx +++ b/src/modules/result/components/ProductModal.tsx @@ -1,3 +1,4 @@ +import { useResultStore } from '@/common/stores/useResultStore' import { Input, Modal, ModalBody, ModalContent, ModalHeader, Pagination, Skeleton, Table, TableBody, TableCell, TableColumn, TableHeader, TableRow } from '@nextui-org/react' import { Product } from '@prisma/client' import { useQuery } from '@tanstack/react-query' @@ -15,18 +16,19 @@ const ProductModal = ({ modal }: Props) => { const [page, setPage] = useState(1) const [search, setSearch] = useState("") const debouncedSearch = useDebounce(search, 500) + const { filter } = useResultStore() useEffect(() => { setPage(1) }, [debouncedSearch]) const { data } = useQuery({ - queryKey: ['product', page, debouncedSearch], + queryKey: ['product', page, debouncedSearch, filter.company], queryFn: async () => { const searchParams = new URLSearchParams({ page: page.toString(), search: debouncedSearch, - type: 'all' + companyId: filter.company }) const response = await fetch(`/api/product?${searchParams}`) const data: { diff --git a/src/modules/result/components/Table.tsx b/src/modules/result/components/Table.tsx index d2e5af4..021dfef 100644 --- a/src/modules/result/components/Table.tsx +++ b/src/modules/result/components/Table.tsx @@ -1,7 +1,7 @@ "use client"; import { useResultStore } from "@/common/stores/useResultStore"; import { StockOpnameRes } from "@/common/types/stockOpname"; -import { Badge, Pagination, Spacer } from "@nextui-org/react" +import { Button, Pagination, Skeleton, Spacer, Spinner } from "@nextui-org/react" import { useQuery } from "@tanstack/react-query"; import { useSearchParams } from "next/navigation"; import { useRouter } from "next/navigation"; @@ -9,31 +9,68 @@ import styles from "./table.module.css" import clsxm from "@/common/libs/clsxm"; import DetailRow from "./DetailRow"; import { useDebounce } from "usehooks-ts"; +import getClientCredential from "@/common/libs/getClientCredential"; +import { SHOWING_SELECTIONS } from "@/common/constants/result"; +import Link from "next/link"; +import { useState } from "react"; const Table = () => { + const credential = getClientCredential() + const params = useSearchParams() const router = useRouter() const page = params.get('page') ?? '1' - const { filter: { company, search } } = useResultStore() + const { filter: { company, search, show } } = useResultStore() const debouncedSearch = useDebounce(search, 500) const stockOpnames = useQuery({ - queryKey: ['stockOpnames', company, debouncedSearch, page], + queryKey: ['stockOpnames', company, debouncedSearch, page, show], queryFn: async () => { const searchParams = new URLSearchParams() if (!company) return null searchParams.set('companyId', company) - searchParams.set('page', page); + + const showValue = SHOWING_SELECTIONS.find((item) => item.key === show)?.value || '' + searchParams.set('show', showValue); + if (debouncedSearch) searchParams.set('search', debouncedSearch) + searchParams.set('page', page); + return await fetch(`/api/stock-opname?${searchParams}`) .then(res => res.json()) }, }) + const { filter } = useResultStore() + + const [exportLoad, setExportLoad] = useState(false) + + const exportResult = async () => { + setExportLoad(true) + const response = await fetch(`/api/stock-opname/export?companyId=${filter.company}`) + const buffer = await response.arrayBuffer() + + const blob = new Blob([buffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }) + const url = window.URL.createObjectURL(blob) + const a = document.createElement('a') + a.href = url + a.download = 'export.xlsx' + document.body.appendChild(a) + a.click() + document.body.removeChild(a) + setExportLoad(false) + } + return ( <> +
+ +
+
@@ -41,6 +78,7 @@ const Table = () => { + @@ -48,13 +86,17 @@ const Table = () => { {stockOpnames.data?.result.map((stockOpname: StockOpnameRes['result']) => ( <> - + + @@ -85,7 +130,19 @@ const Table = () => { {stockOpnames.data?.result.length === 0 && ( - + + + )} + + {stockOpnames.isLoading && ( + + )} diff --git a/src/modules/result/components/filter.module.css b/src/modules/result/components/filter.module.css index 7142d3e..d9171eb 100644 --- a/src/modules/result/components/filter.module.css +++ b/src/modules/result/components/filter.module.css @@ -1,3 +1,3 @@ .wrapper { - @apply flex gap-x-2; + @apply flex flex-wrap gap-y-3; } diff --git a/src/modules/result/components/table.module.css b/src/modules/result/components/table.module.css index c888070..997e9c2 100644 --- a/src/modules/result/components/table.module.css +++ b/src/modules/result/components/table.module.css @@ -17,7 +17,3 @@ first:rounded-md last:rounded-md; } - -.td { - @apply text-neutral-800; -} diff --git a/src/modules/result/index.tsx b/src/modules/result/index.tsx index 73e613a..d69d53f 100644 --- a/src/modules/result/index.tsx +++ b/src/modules/result/index.tsx @@ -13,7 +13,7 @@ const Result = () => { - +
NAMA PRODUK TIM HITUNG 1 TIM HITUNG 2TIM HITUNG 3 TIM VERIFIKASI ON-HAND QTY GUDANG SELISIH
-
- {stockOpname.isDifferent ? 'Tidak Sesuai' : 'Sesuai'} + {stockOpname.isDifferent ? 'Selisih' : 'Aman'}
@@ -63,19 +105,22 @@ const Table = () => { {stockOpname.barcode ? ` [${stockOpname.barcode}]` : ''} - {stockOpname.quantity.COUNT1 || '-'} + {credential?.team == 'VERIFICATION' && typeof stockOpname.quantity.COUNT1 === 'number' ? stockOpname.quantity.COUNT1 : '-'} + + {credential?.team == 'VERIFICATION' && typeof stockOpname.quantity.COUNT2 === 'number' ? stockOpname.quantity.COUNT2 : '-'} - {stockOpname.quantity.COUNT2 || '-'} + {credential?.team == 'VERIFICATION' && typeof stockOpname.quantity.COUNT3 === 'number' ? stockOpname.quantity.COUNT3 : '-'} - {stockOpname.quantity.VERIFICATION || '-'} + {credential?.team == 'VERIFICATION' && typeof stockOpname.quantity.VERIFICATION === 'number' ? stockOpname.quantity.VERIFICATION : '-'} - {stockOpname.onhandQty} + {credential?.team == 'VERIFICATION' ? stockOpname.onhandQty : '-'} - {stockOpname.differenceQty} + {credential?.team == 'VERIFICATION' ? stockOpname.differenceQty : '-'}
Belum ada data untuk ditampilkanBelum ada data untuk ditampilkan
+
+ {Array.from({ length: 6 }, (_, i) => ( + + ))} +
+
) diff --git a/src/modules/stock-opname/index.tsx b/src/modules/stock-opname/index.tsx index 0a5c848..eb8b796 100644 --- a/src/modules/stock-opname/index.tsx +++ b/src/modules/stock-opname/index.tsx @@ -10,7 +10,8 @@ import { useMutation } from "@tanstack/react-query"; import { useEffect, useState } from "react"; import toast from "@/common/libs/toast"; import Scanner from "@/common/components/Scanner"; -import { AlertCircleIcon, ScanIcon, ScanLineIcon } from "lucide-react"; +import { AlertCircleIcon, ScanLineIcon } from "lucide-react"; +import Link from "next/link"; type ActiveScanner = "product" | "location" | null type ScannerOption = { value: number, label: string } @@ -116,7 +117,7 @@ const StockOpname = () => { onChange={handleSelectChange} className="flex-1" /> - @@ -137,7 +138,7 @@ const StockOpname = () => { onChange={handleSelectChange} className="flex-1" /> - @@ -179,6 +180,8 @@ const StockOpname = () => { > {saveMutation.isPending ? : 'Simpan'} + + @@ -195,7 +198,7 @@ const StockOpname = () => { <>
{scannerOptions.map((option) => ( - handleScannerOptionPress(option)}> + handleScannerOptionPress(option)}> {option.label} ))} @@ -245,17 +248,11 @@ const loadProduct = async (inputValue: string) => { const response = await fetch(`/api/product?search=${inputValue}`) const data: { products: Product[] } = await response.json() || [] - return data?.products.map((product) => { - let label = '' - if (product.itemCode) label += `[${product.itemCode}]` - label += ` ${product.name}` - if (product.barcode) label += ` [${product.barcode}]` - - return { - value: product.id, - label - } - }) + return data?.products.map((product) => ({ + value: product.id, + label: `${product.itemCode ? `[${product.itemCode}]` : ''} ${product.name} ${product.barcode ? ` [${product.barcode}]` : ''}` + } + )) } export default StockOpname \ No newline at end of file -- cgit v1.2.3