diff --git a/src/app/(pages)/(main)/assign/page.tsx b/src/app/(pages)/(main)/assign/page.tsx index b2e5067..d7c5d84 100644 --- a/src/app/(pages)/(main)/assign/page.tsx +++ b/src/app/(pages)/(main)/assign/page.tsx @@ -43,10 +43,15 @@ const AssignPage = () => { keyword: "", }); const [selected, setSelected] = useState(null); - const smsAddParam = useMemo(() => selected ? buildPerformanceSmsParams(selected) : {}, [selected]); - const [assignSaveTargetIds, setAssignSaveTargetIds] = useState([]); + + type SmsMode = "assignConfirm" | "normal"; + const [smsMode, setSmsMode] = useState("assignConfirm"); const [smsTargetIds, setSmsTargetIds] = useState([]); + const [smsTemplateIdx, setSmsTemplateIdx] = useState([]); + const [smsDialogTitle, setSmsDialogTitle] = useState(""); + const [newSmsTemplateIdx, setNewSmsTemplateIdx] = useState(undefined); + const smsAddParam = useMemo(() => selected ? buildPerformanceSmsParams(selected) : {}, [selected]); const refreshAssignList = () => { void refetchPerformanceList(); @@ -115,17 +120,35 @@ const AssignPage = () => { return (performance.performanceAssignList ?? []).filter((assign) => assign.assignType === MONITORING_ASSIGN_TYPE); }; + const smsBeforeSendProps = + smsMode === "assignConfirm" + ? { + isBeforeSendPending: saveAssignMutation.isPending, + onBeforeDefaultTemplateSend: async () => { + if (!selected) throw new Error("공연 정보가 없습니다."); + + const monitoringAssigns = await saveAssignMutation.mutateAsync({ + performanceId: selected.id, + userIds: assignSaveTargetIds, + }); + + applySavedAssignsToSelected(selected.id, monitoringAssigns); + }, + onSent: refreshAssignList, + } + : {}; + const columns = useMemo[]>(() => [ - {accessorKey: "id", header: PERFORMANCE_FIELD_LABELS.id, cell: ({row}) => row.original.id, enableSorting: true}, - {accessorKey: "performanceName", header: PERFORMANCE_FIELD_LABELS.performanceName, enableSorting: true}, + {accessorKey: "id", header: PERFORMANCE_FIELD_LABELS.id, cell: ({row}) => row.original.id}, + {accessorKey: "performanceName", header: PERFORMANCE_FIELD_LABELS.performanceName}, {id: "area", header: PERFORMANCE_FIELD_LABELS.performanceArea, cell: ({row}) => getCodeLabel(codes, "area", row.original.performanceArea)}, - {accessorKey: "performanceDtInfo", header: PERFORMANCE_FIELD_LABELS.performanceDtInfo}, - {accessorKey: "performanceTimeInfo", header: PERFORMANCE_FIELD_LABELS.performanceTimeInfo}, - {id: "monitoringDate", header: PERFORMANCE_FIELD_LABELS.monitoringDate, cell: ({row}) => row.original.performanceMonitoringSchedule?.monitoringDate ?? "", enableSorting: true}, + {accessorKey: "performanceDtInfo", header: PERFORMANCE_FIELD_LABELS.performanceDtInfo, enableSorting: false}, + {accessorKey: "performanceTimeInfo", header: PERFORMANCE_FIELD_LABELS.performanceTimeInfo, enableSorting: false}, + {id: "monitoringDate", header: PERFORMANCE_FIELD_LABELS.monitoringDate, accessorFn:(row) => row.performanceMonitoringSchedule?.monitoringDate ?? "", cell: ({row}) => row.original.performanceMonitoringSchedule?.monitoringDate ?? ""}, {id: "monitoringTime", header: PERFORMANCE_FIELD_LABELS.monitoringTimeInfo, cell: ({row}) => row.original.performanceMonitoringSchedule?.monitoringTimeInfo ?? ""}, - {id: "applyCount", header: "신청자 수", cell: ({row}) => applyCountMap.get(String(row.original.id)) ?? 0, enableSorting: true}, - {id: "requestCount", header: "확정요청 수", cell: ({row}) => getMonitoringAssigns(row.original).length}, - {id: "confirmedCount", header: "확정인원 수", cell: ({row}) => getMonitoringAssigns(row.original).filter((assign) => assign.assignConfirm).length}, + {id: "applyCount", header: "신청자 수", accessorFn:((row) => applyCountMap.get(String(row.id)) ?? 0), cell: ({row}) => applyCountMap.get(String(row.original.id)) ?? 0}, + {id: "requestCount", header: "확정요청 수", accessorFn:((row) => getMonitoringAssigns(row).length), cell: ({row}) => getMonitoringAssigns(row.original).length}, + {id: "confirmedCount", header: "확정인원 수", accessorFn:((row) => getMonitoringAssigns(row).filter((assign) => assign.assignConfirm ).length), cell: ({row}) => getMonitoringAssigns(row.original).filter((assign) => assign.assignConfirm).length}, ], [applyCountMap, codes]); if(!mounted) return @@ -172,10 +195,29 @@ const AssignPage = () => { {onSuccess: (monitoringAssigns) => applySavedAssignsToSelected(performanceId, monitoringAssigns)} ) } - onOpenSms={(assignUserIds, smsUserIds) => { + onOpenAssignSms={(assignUserIds, smsUserIds) => { suppressAssignCloseRef.current = true; + setAssignSaveTargetIds(assignUserIds); setSmsTargetIds(smsUserIds); + + setSmsMode("assignConfirm"); + setSmsTemplateIdx([SMS_TEMPLATE_IDS.ASSIGN_CONFIRM]) + setSmsDialogTitle("확정 문자 발송") + setNewSmsTemplateIdx(undefined); + + showDialog("assignSmsSendDialog", false); + }} + onOpenNormalSms={(smsUserIds) => { + suppressAssignCloseRef.current = true; + + setSmsTargetIds(smsUserIds); + + setSmsMode("normal"); + setSmsTemplateIdx([SMS_TEMPLATE_IDS.INFORM_ASSIGN, SMS_TEMPLATE_IDS.REMIND_ASSIGN]) + setSmsDialogTitle("문자 발송") + setNewSmsTemplateIdx(SMS_TEMPLATE_IDS.CUSTOM); + showDialog("assignSmsSendDialog", false); }} /> @@ -195,22 +237,13 @@ const AssignPage = () => { suppressAssignCloseRef.current = false; }, 0); }} - title="확정 문자 발송" - templateIdx={SMS_TEMPLATE_IDS.ASSIGN_CONFIRM} - newMessageTemplateIdx={SMS_TEMPLATE_IDS.CUSTOM} + title={smsDialogTitle} + templateIdx={smsTemplateIdx} + newMessageTemplateIdx={newSmsTemplateIdx} selectedUsers={smsTargetUsers} addParams={smsAddParam} denyParamKeys={["userCmpn", "userTeam", "userRole", "id"]} - isBeforeSendPending={saveAssignMutation.isPending} - onBeforeDefaultTemplateSend={async () => { - if (!selected) throw new Error("공연 정보가 없습니다."); - const monitoringAssigns = await saveAssignMutation.mutateAsync({ - performanceId: selected.id, - userIds: assignSaveTargetIds, - }); - applySavedAssignsToSelected(selected.id, monitoringAssigns); - }} - onSent={refreshAssignList} + {...smsBeforeSendProps} /> ); diff --git a/src/app/(pages)/(main)/performance/page.tsx b/src/app/(pages)/(main)/performance/page.tsx index 7223b15..93f3911 100644 --- a/src/app/(pages)/(main)/performance/page.tsx +++ b/src/app/(pages)/(main)/performance/page.tsx @@ -319,20 +319,22 @@ const PerformancePage = () => { }; const columns = useMemo[]>(() => [ - {accessorKey: "id", header: PERFORMANCE_FIELD_LABELS.id, cell: ({row}) => row.original.id, enableSorting: true}, + {accessorKey: "id", header: PERFORMANCE_FIELD_LABELS.id, cell: ({row}) => row.original.id}, {id: "businessType", header: PERFORMANCE_FIELD_LABELS.businessType, cell: ({row}) => getCodeLabel(codes, "business_type", row.original.businessType)}, {id: "genre", header: PERFORMANCE_FIELD_LABELS.performanceGenre, cell: ({row}) => getCodeLabel(codes, "genre", row.original.performanceGenre)}, {id: "area", header: PERFORMANCE_FIELD_LABELS.performanceArea, cell: ({row}) => getCodeLabel(codes, "area", row.original.performanceArea)}, - {accessorKey: "artistName", header: PERFORMANCE_FIELD_LABELS.artistName, enableSorting: true}, - {accessorKey: "performanceName", header: PERFORMANCE_FIELD_LABELS.performanceName, enableSorting: true}, - {id: "startMonth", header: PERFORMANCE_FIELD_LABELS.performanceStartMonth, cell: ({row}) => `${row.original.performanceStartMonth}월`, enableSorting: true}, - {accessorKey: "performanceDtInfo", header: PERFORMANCE_FIELD_LABELS.performanceDtInfo}, - {accessorKey: "performanceTimeInfo", header: PERFORMANCE_FIELD_LABELS.performanceTimeInfo}, + {accessorKey: "artistName", header: PERFORMANCE_FIELD_LABELS.artistName}, + {accessorKey: "performanceName", header: PERFORMANCE_FIELD_LABELS.performanceName}, + {id: "startMonth", header: PERFORMANCE_FIELD_LABELS.performanceStartMonth, + accessorFn: (row) => row.performanceStartMonth ?? 99, + cell: ({row}) => `${row.original.performanceStartMonth}월`}, + {accessorKey: "performanceDtInfo", header: PERFORMANCE_FIELD_LABELS.performanceDtInfo, enableSorting: false}, + {accessorKey: "performanceTimeInfo", header: PERFORMANCE_FIELD_LABELS.performanceTimeInfo, enableSorting: false}, ...(!isWrittenReviewer ? [{ id: "monitoringDate", header: PERFORMANCE_FIELD_LABELS.monitoringDate, + accessorFn: (row) => row.performanceMonitoringSchedule?.monitoringDate ?? "", cell: ({row}) => row.original.performanceMonitoringSchedule?.monitoringDate ?? "", - enableSorting: true, } satisfies DataTableColumn] : []), { id: "localReview", diff --git a/src/app/(pages)/(main)/user/page.tsx b/src/app/(pages)/(main)/user/page.tsx index 015ead1..d1ce30f 100644 --- a/src/app/(pages)/(main)/user/page.tsx +++ b/src/app/(pages)/(main)/user/page.tsx @@ -172,12 +172,12 @@ const UserPage = () => { const columns = useMemo[]>(() => { const commonColumns: DataTableColumn[] = [ - {accessorKey: "userId", header: USER_FIELD_LABELS.userId, enableSorting: true}, + {accessorKey: "userId", header: USER_FIELD_LABELS.userId}, {id: "password", header: "PW", cell: () => "****"}, ]; const monitoringColumns: DataTableColumn[] = [ - {id: "participationCount", header: "참여 횟수", cell: ({row}) => assignCountMap.get(row.original.userId) ?? 0, enableSorting: true}, + {id: "participationCount", header: "참여 횟수", accessorFn: (row) => assignCountMap.get(row.userId) ?? 0, cell: ({row}) => assignCountMap.get(row.original.userId) ?? 0}, {id: "userArea", header: USER_FIELD_LABELS.userArea, cell: ({row}) => renderEditableCell(row.original, "userArea", "select", codes.area)}, {id: "userGender", header: USER_FIELD_LABELS.gender, cell: ({row}) => renderEditableCell(row.original, "userGender", "select", codes.gender)}, {id: "userAge", header: USER_FIELD_LABELS.userAge, cell: ({row}) => renderEditableCell(row.original, "userAge")}, @@ -311,7 +311,7 @@ const UserPage = () => { hideDialog("userSmsSendDialog"); refreshUserList(); }} - templateIdx={SMS_TEMPLATE_IDS.ACCOUNT_MONITORING} + templateIdx={[SMS_TEMPLATE_IDS.ACCOUNT_MONITORING]} newMessageTemplateIdx={SMS_TEMPLATE_IDS.CUSTOM} selectedUsers={smsTargetUsers} onSent={refreshUserList} diff --git a/src/components/dialog/AssignMonitoringDialog.tsx b/src/components/dialog/AssignMonitoringDialog.tsx index aa6352a..f4b7129 100644 --- a/src/components/dialog/AssignMonitoringDialog.tsx +++ b/src/components/dialog/AssignMonitoringDialog.tsx @@ -24,7 +24,8 @@ export function AssignMonitoringDialog({ applyUsers, isSavingAssign, onSaveAssign, - onOpenSms, + onOpenAssignSms, + onOpenNormalSms, }: Readonly<{ open: boolean; onOpenChange: (open: boolean) => void; @@ -33,7 +34,8 @@ export function AssignMonitoringDialog({ applyUsers: MonitoringApplyUser[]; isSavingAssign?: boolean; onSaveAssign: (performanceId: number, userIds: string[]) => void; - onOpenSms: (assignUserIds: string[], smsUserIds: string[]) => void; + onOpenAssignSms: (assignUserIds: string[], smsUserIds: string[]) => void; + onOpenNormalSms: (smsUserIds: string[]) => void; }>) { const monitoringAssigns = useMemo( () => (selected?.performanceAssignList ?? []).filter((item) => item.assignType === MONITORING_ASSIGN_TYPE), @@ -52,7 +54,7 @@ export function AssignMonitoringDialog({ const confirmRequestCount = monitoringAssigns.length; const confirmedCount = monitoringAssigns.filter((item) => item.assignConfirm).length; - const smsTargetIds = checkedIds.filter( + const assignSmsTargetIds = checkedIds.filter( (userId) => !monitoringAssigns.some((assign) => assign.assignUser === userId && assign.assignConfirm) ); @@ -209,10 +211,14 @@ export function AssignMonitoringDialog({ 저장 - + diff --git a/src/components/dialog/SmsSendDialog.tsx b/src/components/dialog/SmsSendDialog.tsx index 04d13ed..cf8a3a6 100644 --- a/src/components/dialog/SmsSendDialog.tsx +++ b/src/components/dialog/SmsSendDialog.tsx @@ -1,11 +1,13 @@ "use client"; import {useEffect, useMemo, useRef, useState} from "react"; -import {Edit, RotateCcw, Save, Send} from "lucide-react"; +import {Edit, RotateCcw, Save, Send, X} from "lucide-react"; import {Button} from "@/components/ui/button"; import {Input} from "@/components/ui/input"; +import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from "@/components/ui/select"; import { Dialog, + DialogClose, DialogContent, DialogFooter, DialogHeader, @@ -14,6 +16,7 @@ import { import { NOTIFICATION_REQUEST_SERVICE, useNotificationTemplateQuery, + useNotificationTemplatesQuery, useSaveNotificationTemplateMutation, useSendSmsBulkMutation, } from "@/query/notification"; @@ -30,11 +33,11 @@ const EMPTY_DENY_PARAM_KEYS: string[] = []; const toText = (value: string | null | undefined) => value ?? ""; -const toDraft = (template: Template, emptyBody = false): TemplateDraft => ({ +const toDraft = (template: Template, isNewMessage = false): TemplateDraft => ({ tmplatIdx: template.tmplatIdx, tmplatNm: toText(template.tmplatNm), - tmplatTitle: toText(template.tmplatTitle), - tmplatBody: emptyBody ? "" : toText(template.tmplatBody), + tmplatTitle: isNewMessage ? "" : toText(template.tmplatTitle), + tmplatBody: isNewMessage ? "" : toText(template.tmplatBody), sendTel: toText(template.sendTel), }); @@ -54,7 +57,7 @@ export function SmsSendDialog({ open: boolean; onOpenChange: (open: boolean) => void; title?: string; - templateIdx: number; + templateIdx: number[]; newMessageTemplateIdx?: number; selectedUsers: UserCompact[]; addParams?: Record; @@ -64,17 +67,28 @@ export function SmsSendDialog({ onSent?: () => void; }>) { const {auth} = useAuth(); - const [activeTemplateIdx, setActiveTemplateIdx] = useState(templateIdx); + const templateIdxKey = templateIdx.join(","); + const templateIdxList = useMemo( + () => Array.from(new Set(templateIdx.filter((idx) => idx > 0))), + [templateIdxKey] + ); + const defaultTemplateIdx = templateIdxList[0] ?? 0; + + const [activeTemplateIdx, setActiveTemplateIdx] = useState(defaultTemplateIdx); const [isNewMessage, setIsNewMessage] = useState(false); const [isEditing, setIsEditing] = useState(false); const [draft, setDraft] = useState(null); const bodyTextareaRef = useRef(null); - const templateQuery = useNotificationTemplateQuery(activeTemplateIdx, open); + const templatesQuery = useNotificationTemplatesQuery(templateIdxList, open); + const newMessageTemplateQuery = useNotificationTemplateQuery(newMessageTemplateIdx ?? 0, Boolean(open && isNewMessage && newMessageTemplateIdx)); const saveTemplateMutation = useSaveNotificationTemplateMutation(); const sendSmsMutation = useSendSmsBulkMutation(); + const activeTemplate = isNewMessage + ? newMessageTemplateQuery.data + : templatesQuery.data.find((template) => template.tmplatIdx === activeTemplateIdx); - const isBusy = templateQuery.isLoading || saveTemplateMutation.isPending || sendSmsMutation.isPending || isBeforeSendPending; + const isBusy = templatesQuery.isLoading || newMessageTemplateQuery.isLoading || saveTemplateMutation.isPending || sendSmsMutation.isPending || isBeforeSendPending; const canEdit = isNewMessage || isEditing; const denyParamKeySet = useMemo(() => new Set(denyParamKeys), [denyParamKeys]); @@ -108,18 +122,18 @@ export function SmsSendDialog({ useEffect(() => { if (!open) return; - setActiveTemplateIdx(templateIdx); + setActiveTemplateIdx(defaultTemplateIdx); setIsNewMessage(false); setIsEditing(false); setDraft(null); - }, [open, templateIdx]); + }, [defaultTemplateIdx, open]); useEffect(() => { - if (!open || !templateQuery.data) return; + if (!open || !activeTemplate) return; - setDraft(toDraft(templateQuery.data, isNewMessage)); + setDraft(toDraft(activeTemplate, isNewMessage)); setIsEditing(false); - }, [isNewMessage, open, templateQuery.data]); + }, [activeTemplate, isNewMessage, open]); const updateDraft = (key: K, value: TemplateDraft[K]) => { setDraft((prev) => prev ? {...prev, [key]: value} : prev); @@ -162,12 +176,19 @@ export function SmsSendDialog({ }; const cancelEdit = () => { - if (templateQuery.data) { - setDraft(toDraft(templateQuery.data, isNewMessage)); + if (activeTemplate) { + setDraft(toDraft(activeTemplate, isNewMessage)); } setIsEditing(false); }; + const changeTemplate = (value: string) => { + setActiveTemplateIdx(Number(value)); + setIsNewMessage(false); + setIsEditing(false); + setDraft(null); + }; + const switchToNewMessage = () => { if (!newMessageTemplateIdx) return; @@ -178,7 +199,7 @@ export function SmsSendDialog({ }; const restoreTemplate = () => { - setActiveTemplateIdx(templateIdx); + setActiveTemplateIdx(defaultTemplateIdx); setIsNewMessage(false); setIsEditing(false); setDraft(null); @@ -227,14 +248,11 @@ export function SmsSendDialog({ return ( - - + + {title} - - -
-
-
+
+
선택 인원: {selectedUsers.length}명 {destinations.length !== selectedUsers.length && ( 발송 가능 {destinations.length}명 @@ -252,9 +270,17 @@ export function SmsSendDialog({ ) )} + + +
+ - {templateQuery.isLoading && ( +
+ {(templatesQuery.isLoading || newMessageTemplateQuery.isLoading) && (
템플릿 정보를 불러오는 중입니다.
)} @@ -263,7 +289,27 @@ export function SmsSendDialog({
{msgParamKeys.length > 0 && (
사용 가능 변수값
-
+
+
{msgParamKeys.map((key) => ( ))} +
)} diff --git a/src/query/notification.ts b/src/query/notification.ts index 2083382..fd5af79 100644 --- a/src/query/notification.ts +++ b/src/query/notification.ts @@ -1,6 +1,6 @@ "use client"; -import {useMutation, useQuery} from "@tanstack/react-query"; +import {useMutation, useQueries, useQuery} from "@tanstack/react-query"; import {nextApi} from "@/lib/http-client"; import {BulkSendResponse, SaveTemplateRequest, SendSmsBulkRequest, Template} from "@/types/notification"; @@ -8,6 +8,8 @@ export const SMS_TEMPLATE_IDS = { ACCOUNT_MONITORING: 45, ASSIGN_CONFIRM: 46, CUSTOM: 47, + INFORM_ASSIGN: 48, + REMIND_ASSIGN: 49, } as const; export const NOTIFICATION_REQUEST_SERVICE = "gwcf-review"; @@ -20,6 +22,21 @@ export function useNotificationTemplateQuery(templateIdx: number, enabled = true }); } +export function useNotificationTemplatesQuery(templateIdxList: number[], enabled = true) { + return useQueries({ + queries: templateIdxList.map((templateIdx) => ({ + queryKey: ["notification", "template", templateIdx], + queryFn: () => nextApi.get