diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-10-24 09:52:35 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-10-24 09:52:35 +0000 |
| commit | 0174ad394032a8dad81107341f477d6d23a3c04c (patch) | |
| tree | 6be84f638a852e6d0cea057b67e462e78fc65d41 /lib/pq/pq-review-table-new/pq-filter-sheet.tsx | |
| parent | 912e2bc761d7d57bd33d68cb5050da43dea59636 (diff) | |
(최겸) 구매 피드백 수정(PQ, 실사 등)-1024
Diffstat (limited to 'lib/pq/pq-review-table-new/pq-filter-sheet.tsx')
| -rw-r--r-- | lib/pq/pq-review-table-new/pq-filter-sheet.tsx | 247 |
1 files changed, 210 insertions, 37 deletions
diff --git a/lib/pq/pq-review-table-new/pq-filter-sheet.tsx b/lib/pq/pq-review-table-new/pq-filter-sheet.tsx index ff1b890b..fe525a46 100644 --- a/lib/pq/pq-review-table-new/pq-filter-sheet.tsx +++ b/lib/pq/pq-review-table-new/pq-filter-sheet.tsx @@ -7,7 +7,7 @@ import { useForm } from "react-hook-form" import { zodResolver } from "@hookform/resolvers/zod"
import { CalendarIcon, ChevronRight, Search, X } from "lucide-react"
import { customAlphabet } from "nanoid"
-import { parseAsStringEnum, useQueryState } from "nuqs"
+import { parseAsStringEnum, useQueryState, parseAsString } from "nuqs"
import { Button } from "@/components/ui/button"
import {
@@ -40,8 +40,11 @@ const pqFilterSchema = z.object({ requesterName: z.string().optional(),
pqNumber: z.string().optional(),
vendorName: z.string().optional(),
+ vendorCode: z.string().optional(),
+ type: z.string().optional(),
+ projectName: z.string().optional(),
status: z.string().optional(),
- evaluationResult: z.string().optional(),
+ pqItems: z.string().optional(),
createdAtRange: z.object({
from: z.date().optional(),
to: z.date().optional(),
@@ -57,13 +60,13 @@ const pqStatusOptions = [ { value: "REJECTED", label: "거부됨" },
]
-// 평가 결과 옵션 정의
-const evaluationResultOptions = [
- { value: "APPROVED", label: "승인" },
- { value: "SUPPLEMENT", label: "보완" },
- { value: "REJECTED", label: "불가" },
+// PQ 유형 옵션 정의
+const pqTypeOptions = [
+ { value: "GENERAL", label: "일반 PQ" },
+ { value: "PROJECT", label: "프로젝트 PQ" },
]
+
type PQFilterFormValues = z.infer<typeof pqFilterSchema>
interface PQFilterSheetProps {
@@ -106,6 +109,10 @@ export function PQFilterSheet({ // 현재 URL의 페이지 파라미터도 가져옴
const [page, setPage] = useQueryState("page", { defaultValue: "1" })
+ // DateRangePicker의 from/to 파라미터 직접 읽기
+ const [fromParam, setFromParam] = useQueryState("from", parseAsString.withDefault(""))
+ const [toParam, setToParam] = useQueryState("to", parseAsString.withDefault(""))
+
// 폼 상태 초기화
const form = useForm<PQFilterFormValues>({
resolver: zodResolver(pqFilterSchema),
@@ -113,8 +120,11 @@ export function PQFilterSheet({ requesterName: "",
pqNumber: "",
vendorName: "",
+ vendorCode: "",
+ type: "",
+ projectName: "",
status: "",
- evaluationResult: "",
+ pqItems: "",
createdAtRange: {
from: undefined,
to: undefined,
@@ -128,12 +138,22 @@ export function PQFilterSheet({ const currentFiltersString = JSON.stringify(filters);
// 패널이 열렸고, 필터가 있고, 마지막에 적용된 필터와 다를 때만 업데이트
- if (isOpen && filters && filters.length > 0 && currentFiltersString !== lastAppliedFilters.current) {
+ if (isOpen && (filters && filters.length > 0 || fromParam || toParam) && currentFiltersString !== lastAppliedFilters.current) {
setIsInitializing(true);
const formValues = { ...form.getValues() };
let formUpdated = false;
+ // DateRangePicker의 from/to 파라미터 처리
+ if (fromParam || toParam) {
+ formValues.createdAtRange = {
+ from: fromParam ? new Date(fromParam) : undefined,
+ to: toParam ? new Date(toParam) : undefined,
+ };
+ formUpdated = true;
+ }
+
+ // 기존 필터 처리
filters.forEach(filter => {
if (filter.id === "createdAt" && Array.isArray(filter.value) && filter.value.length > 0) {
formValues.createdAtRange = {
@@ -156,7 +176,7 @@ export function PQFilterSheet({ setIsInitializing(false);
}
- }, [filters, isOpen])
+ }, [filters, fromParam, toParam, isOpen])
// 현재 적용된 필터 카운트
const getActiveFilterCount = () => {
@@ -171,7 +191,13 @@ async function onSubmit(data: PQFilterFormValues) { startTransition(async () => {
try {
// 필터 배열 생성
- const newFilters = []
+ const newFilters: Array<{
+ id: string;
+ value: string | string[];
+ type: string;
+ operator: string;
+ rowId: string;
+ }> = []
if (data.requesterName?.trim()) {
newFilters.push({
@@ -203,6 +229,36 @@ async function onSubmit(data: PQFilterFormValues) { })
}
+ if (data.vendorCode?.trim()) {
+ newFilters.push({
+ id: "vendorCode",
+ value: data.vendorCode.trim(),
+ type: "text",
+ operator: "iLike",
+ rowId: generateId()
+ })
+ }
+
+ if (data.type?.trim()) {
+ newFilters.push({
+ id: "type",
+ value: data.type.trim(),
+ type: "select",
+ operator: "eq",
+ rowId: generateId()
+ })
+ }
+
+ if (data.projectName?.trim()) {
+ newFilters.push({
+ id: "projectName",
+ value: data.projectName.trim(),
+ type: "text",
+ operator: "iLike",
+ rowId: generateId()
+ })
+ }
+
if (data.status?.trim()) {
newFilters.push({
id: "status",
@@ -213,24 +269,24 @@ async function onSubmit(data: PQFilterFormValues) { })
}
- if (data.evaluationResult?.trim()) {
+ if (data.pqItems?.trim()) {
newFilters.push({
- id: "evaluationResult",
- value: data.evaluationResult.trim(),
- type: "select",
- operator: "eq",
+ id: "pqItems",
+ value: data.pqItems.trim(),
+ type: "text",
+ operator: "iLike",
rowId: generateId()
})
}
- // 생성일 범위 추가
+ // PQ 전송일 범위 추가 (createdAt)
if (data.createdAtRange?.from) {
newFilters.push({
id: "createdAt",
value: [
data.createdAtRange.from.toISOString().split('T')[0],
- data.createdAtRange.to ? data.createdAtRange.to.toISOString().split('T')[0] : undefined
- ].filter(Boolean),
+ data.createdAtRange.to?.toISOString().split('T')[0]
+ ].filter((v): v is string => v !== undefined),
type: "date",
operator: "isBetween",
rowId: generateId()
@@ -289,8 +345,11 @@ async function onSubmit(data: PQFilterFormValues) { requesterName: "",
pqNumber: "",
vendorName: "",
+ vendorCode: "",
+ type: "",
+ projectName: "",
status: "",
- evaluationResult: "",
+ pqItems: "",
createdAtRange: { from: undefined, to: undefined },
});
@@ -373,11 +432,11 @@ async function onSubmit(data: PQFilterFormValues) { name="requesterName"
render={({ field }) => (
<FormItem>
- <FormLabel>요청자명</FormLabel>
+ <FormLabel>PQ/실사 요청자</FormLabel>
<FormControl>
<div className="relative">
<Input
- placeholder="요청자명 입력"
+ placeholder="PQ/실사 요청자 입력"
{...field}
className={cn(field.value && "pr-8", "bg-white")}
disabled={isInitializing}
@@ -411,11 +470,11 @@ async function onSubmit(data: PQFilterFormValues) { name="pqNumber"
render={({ field }) => (
<FormItem>
- <FormLabel>PQ 번호</FormLabel>
+ <FormLabel>PQ No.</FormLabel>
<FormControl>
<div className="relative">
<Input
- placeholder="PQ 번호 입력"
+ placeholder="PQ No. 입력"
{...field}
className={cn(field.value && "pr-8", "bg-white")}
disabled={isInitializing}
@@ -449,7 +508,7 @@ async function onSubmit(data: PQFilterFormValues) { name="vendorName"
render={({ field }) => (
<FormItem>
- <FormLabel>협력업체명</FormLabel>
+ <FormLabel>협력업체</FormLabel>
<FormControl>
<div className="relative">
<Input
@@ -482,7 +541,7 @@ async function onSubmit(data: PQFilterFormValues) { />
{/* PQ 상태 */}
- <FormField
+ {/* <FormField
control={form.control}
name="status"
render={({ field }) => (
@@ -527,15 +586,15 @@ async function onSubmit(data: PQFilterFormValues) { <FormMessage />
</FormItem>
)}
- />
+ /> */}
- {/* 평가 결과 */}
+ {/* PQ 유형 */}
<FormField
control={form.control}
- name="evaluationResult"
+ name="type"
render={({ field }) => (
<FormItem>
- <FormLabel>평가 결과</FormLabel>
+ <FormLabel>PQ 유형</FormLabel>
<Select
value={field.value}
onValueChange={field.onChange}
@@ -544,7 +603,7 @@ async function onSubmit(data: PQFilterFormValues) { <FormControl>
<SelectTrigger className={cn(field.value && "pr-8", "bg-white")}>
<div className="flex justify-between w-full">
- <SelectValue placeholder="평가 결과 선택" />
+ <SelectValue placeholder="PQ 유형 선택" />
{field.value && (
<Button
type="button"
@@ -553,7 +612,7 @@ async function onSubmit(data: PQFilterFormValues) { className="h-4 w-4 -mr-2"
onClick={(e) => {
e.stopPropagation();
- form.setValue("evaluationResult", "");
+ form.setValue("type", "");
}}
disabled={isInitializing}
>
@@ -565,7 +624,7 @@ async function onSubmit(data: PQFilterFormValues) { </SelectTrigger>
</FormControl>
<SelectContent>
- {evaluationResultOptions.map(option => (
+ {pqTypeOptions.map(option => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
@@ -577,13 +636,127 @@ async function onSubmit(data: PQFilterFormValues) { )}
/>
- {/* PQ 생성일 */}
+ {/* 프로젝트명 */}
+ {/* <FormField
+ control={form.control}
+ name="projectName"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>프로젝트명</FormLabel>
+ <FormControl>
+ <div className="relative">
+ <Input
+ placeholder="프로젝트명 입력"
+ {...field}
+ className={cn(field.value && "pr-8", "bg-white")}
+ disabled={isInitializing}
+ />
+ {field.value && (
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="absolute right-0 top-0 h-full px-2"
+ onClick={(e) => {
+ e.stopPropagation();
+ form.setValue("projectName", "");
+ }}
+ disabled={isInitializing}
+ >
+ <X className="size-3.5" />
+ <span className="sr-only">Clear</span>
+ </Button>
+ )}
+ </div>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ /> */}
+
+ {/* 협력업체 코드 */}
+ <FormField
+ control={form.control}
+ name="vendorCode"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>협력업체 코드</FormLabel>
+ <FormControl>
+ <div className="relative">
+ <Input
+ placeholder="협력업체 코드 입력"
+ {...field}
+ className={cn(field.value && "pr-8", "bg-white")}
+ disabled={isInitializing}
+ />
+ {field.value && (
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="absolute right-0 top-0 h-full px-2"
+ onClick={(e) => {
+ e.stopPropagation();
+ form.setValue("vendorCode", "");
+ }}
+ disabled={isInitializing}
+ >
+ <X className="size-3.5" />
+ <span className="sr-only">Clear</span>
+ </Button>
+ )}
+ </div>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* 실사품목 */}
+ <FormField
+ control={form.control}
+ name="pqItems"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>실사품목</FormLabel>
+ <FormControl>
+ <div className="relative">
+ <Input
+ placeholder="실사품목 입력"
+ {...field}
+ className={cn(field.value && "pr-8", "bg-white")}
+ disabled={isInitializing}
+ />
+ {field.value && (
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ className="absolute right-0 top-0 h-full px-2"
+ onClick={(e) => {
+ e.stopPropagation();
+ form.setValue("pqItems", "");
+ }}
+ disabled={isInitializing}
+ >
+ <X className="size-3.5" />
+ <span className="sr-only">Clear</span>
+ </Button>
+ )}
+ </div>
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+
+ {/* PQ 전송일 */}
<FormField
control={form.control}
name="createdAtRange"
render={({ field }) => (
<FormItem>
- <FormLabel>PQ 생성일</FormLabel>
+ <FormLabel>PQ 전송일 범위</FormLabel>
<FormControl>
<div className="relative">
<DateRangePicker
@@ -591,8 +764,8 @@ async function onSubmit(data: PQFilterFormValues) { triggerClassName="w-full bg-white"
align="start"
showClearButton={true}
- placeholder="PQ 생성일 범위를 선택하세요"
- value={field.value || undefined}
+ placeholder="PQ 전송일 범위를 선택하세요"
+ defaultDateRange={field.value?.from ? field.value : undefined}
onChange={field.onChange}
disabled={isInitializing}
/>
|
