diff --git a/src/components/hr/CalendarManagement/BulkRegistrationDialog.tsx b/src/components/hr/CalendarManagement/BulkRegistrationDialog.tsx index b2330c90..2c6f8986 100644 --- a/src/components/hr/CalendarManagement/BulkRegistrationDialog.tsx +++ b/src/components/hr/CalendarManagement/BulkRegistrationDialog.tsx @@ -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 = { @@ -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); diff --git a/src/components/hr/CalendarManagement/index.tsx b/src/components/hr/CalendarManagement/index.tsx index 5c401c0c..323faad1 100644 --- a/src/components/hr/CalendarManagement/index.tsx +++ b/src/components/hr/CalendarManagement/index.tsx @@ -285,6 +285,7 @@ export function CalendarManagement() { open={bulkOpen} onOpenChange={setBulkOpen} onSuccess={loadData} + schedules={schedules} /> );