fix: [calendar] 대량 등록 다이얼로그 기존 데이터 표시 기능 추가
- BulkRegistrationDialog에 schedules prop 추가 - 다이얼로그 열릴 때 기존 등록 데이터를 텍스트로 변환하여 표시 - MNG 대량 등록과 동일한 동작
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useMemo } from 'react';
|
||||
import { useState, useMemo, useEffect } from 'react';
|
||||
import { Loader2, Info } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { toast } from 'sonner';
|
||||
import type { BulkScheduleItem, CalendarScheduleType } from './types';
|
||||
import type { BulkScheduleItem, CalendarSchedule, CalendarScheduleType } from './types';
|
||||
import { SCHEDULE_TYPE_LABELS, SCHEDULE_TYPE_BADGE_COLORS } from './types';
|
||||
import { bulkCreateCalendarSchedules } from './actions';
|
||||
|
||||
@@ -15,6 +15,7 @@ interface BulkRegistrationDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onSuccess: () => void;
|
||||
schedules?: CalendarSchedule[];
|
||||
}
|
||||
|
||||
const TYPE_KEYWORD_MAP: Record<string, CalendarScheduleType> = {
|
||||
@@ -65,10 +66,28 @@ function parseBulkText(text: string): BulkScheduleItem[] {
|
||||
return items;
|
||||
}
|
||||
|
||||
export function BulkRegistrationDialog({ open, onOpenChange, onSuccess }: BulkRegistrationDialogProps) {
|
||||
function schedulesToText(schedules: CalendarSchedule[]): string {
|
||||
return schedules.map((s) => {
|
||||
const datePart = s.startDate === s.endDate ? s.startDate : `${s.startDate}~${s.endDate}`;
|
||||
const typePart = s.type !== 'publicHoliday' ? ` [${SCHEDULE_TYPE_LABELS[s.type]}]` : '';
|
||||
return `${datePart} ${s.name}${typePart}`;
|
||||
}).join('\n');
|
||||
}
|
||||
|
||||
export function BulkRegistrationDialog({ open, onOpenChange, onSuccess, schedules }: BulkRegistrationDialogProps) {
|
||||
const [text, setText] = useState('');
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
if (schedules && schedules.length > 0) {
|
||||
setText(schedulesToText(schedules));
|
||||
} else {
|
||||
setText('');
|
||||
}
|
||||
}
|
||||
}, [open, schedules]);
|
||||
|
||||
const parsedItems = useMemo(() => parseBulkText(text), [text]);
|
||||
const validItems = parsedItems.filter((item) => item.isValid);
|
||||
|
||||
|
||||
@@ -285,6 +285,7 @@ export function CalendarManagement() {
|
||||
open={bulkOpen}
|
||||
onOpenChange={setBulkOpen}
|
||||
onSuccess={loadData}
|
||||
schedules={schedules}
|
||||
/>
|
||||
</PageLayout>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user