feat: 일정 등록 기능

This commit is contained in:
2025-05-27 13:23:56 +09:00
parent d351b8e24e
commit a9887eaac6
16 changed files with 792 additions and 3 deletions
@@ -0,0 +1,24 @@
import { client } from "@/shared/api";
import { ENDPOINT } from "@/shared/config";
import type {
Schedule,
ScheduleFormData,
ScheduleParams,
ScheduleService,
} from "../model/schedule-interface";
class ScheduleApiService implements ScheduleService {
public async getSchedules(params?: ScheduleParams): Promise<Schedule[]> {
const response = await client.get<Schedule[]>(
ENDPOINT.CMS_SERVICE.SCHEDULES,
{ params },
);
return response.data;
}
public async createSchedule(data: ScheduleFormData): Promise<void> {
await client.post(ENDPOINT.CMS_SERVICE.SCHEDULES, data);
}
}
export const ScheduleApi = new ScheduleApiService();
+2
View File
@@ -0,0 +1,2 @@
export { SchedulePage } from "./ui/schedule-page";
export { CreatePage } from "./ui/create-page";
@@ -0,0 +1,55 @@
import { z } from "zod";
export interface ScheduleParams {
siteId?: string;
schdlTtl?: string;
schdlSeCd?: string;
schdlBgngYmd?: string;
schdlEndYmd?: string;
reptYn?: string;
commSchdlYn?: string;
useYn?: string;
}
export interface Schedule {
schdlSn: number;
siteId: string;
schdlTtl: string;
schdlSeCd: string;
schdlSeNm: string;
schdlBgngDt: string;
schdlEndDt: string;
reptYn: string;
commSchdlYn: string;
}
const scheduleRepeatSchema = z.object({
schdlSn: z.number().nullish(),
reptCycleCd: z.string().nullish(),
reptDayVl: z.number().nullish(),
reptDowVl: z.number().nullish(),
reptMmVl: z.number().nullish(),
reptQuVl: z.number().nullish(),
reptEndDt: z.string().nullish(),
});
export const scheduleFormSchema = z.object({
siteId: z.string(),
schdlTtl: z.string(),
schdlSeCd: z.string(),
schdlBgngDt: z.string(),
schdlEndDt: z.string(),
schdlCn: z.string().nullish(),
reptYn: z.string().nullish(),
commSchdlYn: z.string().nullish(),
useYn: z.string().nullish(),
atflCd: z.string().nullish(),
reptDto: scheduleRepeatSchema.nullish(),
});
export type ScheduleFormData = z.infer<typeof scheduleFormSchema>;
export interface ScheduleService {
getSchedules(params?: ScheduleParams): Promise<Schedule[]>;
createSchedule(data: ScheduleFormData): Promise<void>;
}
@@ -0,0 +1,66 @@
"use client";
import dayjs from "dayjs";
import { useForm } from "react-hook-form";
import { useRouter, useSearchParams } from "next/navigation";
import { useMutation } from "@tanstack/react-query";
import { zodResolver } from "@hookform/resolvers/zod";
import { useAlertStore } from "@/shared/lib";
import { SITE_ID } from "@/shared/config";
import {
scheduleFormSchema,
type ScheduleFormData,
} from "../model/schedule-interface";
import { ScheduleApi } from "../api/schedule-service";
import { ScheduleForm } from "./schedule-form";
function CreatePage() {
const router = useRouter();
const searchParams = useSearchParams();
const dateStr = searchParams?.get("dateStr");
const { setMessage: alert } = useAlertStore((state) => state);
const { mutateAsync: createSchedule } = useMutation({
mutationFn: ScheduleApi.createSchedule,
onSuccess: () => {
alert("일정이 등록되었습니다.", router.back);
},
});
const form = useForm<ScheduleFormData>({
resolver: zodResolver(scheduleFormSchema),
defaultValues: {
siteId: SITE_ID,
schdlBgngDt: dateStr
? dayjs(dateStr).format("YYYY-MM-DD 00:00:00")
: undefined,
schdlEndDt: dateStr
? dayjs(dateStr).format("YYYY-MM-DD 23:59:59")
: undefined,
reptYn: "N",
commSchdlYn: "N",
useYn: "Y",
atflCd: null,
reptDto: null,
},
});
const handleSave = async (data: ScheduleFormData) => {
// const reptDtoValid = Object.values(data.reptDto ?? {}).every(
// (value) => value === null,
// );
// if (reptDtoValid) data.reptDto = null;
await createSchedule(data);
};
return (
<div className="card card-border !mb-0 !mt-6">
<div className="card-header">
<h3 className="text-2xl font-medium text-label">스케줄 등록</h3>
</div>
<ScheduleForm form={form} handleSave={handleSave} />
</div>
);
}
export { CreatePage };
@@ -0,0 +1,123 @@
"use client";
import dayjs from "dayjs";
import { useState } from "react";
import { CalendarIcon } from "lucide-react";
import {
Button,
Calendar,
Popover,
PopoverContent,
PopoverTrigger,
ScrollArea,
ScrollBar,
cn,
} from "@common/components";
type DateTimePickerProps = {
date?: Date;
classes?: { trigger?: string };
onDateChange?: (date: Date) => void;
};
function DateTimePicker({ date, classes, onDateChange }: DateTimePickerProps) {
const [isOpen, setIsOpen] = useState(false);
const hours = Array.from({ length: 24 }, (_, i) => i);
const minutes = Array.from({ length: 60 }, (_, i) => i);
const handleDateSelect = (selectedDate: Date | undefined) => {
if (!selectedDate) return;
onDateChange?.(selectedDate);
};
const handleTimeChange = (type: "hour" | "minute", value: string) => {
if (date) {
const newDate = new Date(date);
if (type === "hour") {
newDate.setHours(parseInt(value));
} else if (type === "minute") {
newDate.setMinutes(parseInt(value));
}
onDateChange?.(newDate);
}
};
return (
<Popover open={isOpen} onOpenChange={setIsOpen}>
<PopoverTrigger asChild>
<Button
variant="outline"
className={cn(
"date-picker-trigger",
!date && "text-muted-foreground",
classes?.trigger,
)}
>
<CalendarIcon className="!size-[1.6rem]" />
{date ? (
dayjs(date).format("YYYY/MM/DD HH:mm")
) : (
<span>YYYY/MM/DD HH:mm</span>
)}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0">
<div className="sm:flex">
<Calendar
mode="single"
selected={date}
onSelect={handleDateSelect}
initialFocus
/>
<div className="flex flex-col divide-y sm:h-[300px] sm:flex-row sm:divide-x sm:divide-y-0">
<ScrollArea className="w-64 sm:w-auto">
<div className="flex p-2 sm:flex-col">
{hours.reverse().map((hour) => (
<Button
key={hour}
size="icon"
className={cn(
"aspect-square shrink-0 text-label sm:w-full",
date && date.getHours() === hour
? "!bg-primary text-primary-foreground"
: "!bg-background",
)}
onClick={() => handleTimeChange("hour", hour.toString())}
>
{hour}
</Button>
))}
</div>
<ScrollBar orientation="horizontal" className="sm:hidden" />
</ScrollArea>
<ScrollArea className="w-64 sm:w-auto">
<div className="flex p-2 sm:flex-col">
{minutes.map((minute) => (
<Button
key={minute}
size="icon"
className={cn(
"aspect-square shrink-0 text-label sm:w-full",
date && date.getMinutes() === minute
? "!bg-primary text-primary-foreground"
: "!bg-background",
)}
onClick={() =>
handleTimeChange("minute", minute.toString())
}
>
{minute.toString().padStart(2, "0")}
</Button>
))}
</div>
<ScrollBar orientation="horizontal" className="sm:hidden" />
</ScrollArea>
</div>
</div>
</PopoverContent>
</Popover>
);
}
export { DateTimePicker };
@@ -0,0 +1,331 @@
import dayjs from "dayjs";
import { useState } from "react";
import { type UseFormReturn } from "react-hook-form";
import {
Checkbox,
DatePicker,
Input,
Label,
RadioGroup,
RadioGroupItem,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
Textarea,
} from "@common/components";
import { GeneralFileUploader } from "@/widgets/post/ui/general-file-uploader";
import { FormWrapper } from "@/widgets/form-wrapper";
import { CodeSelect } from "@/entities/code";
import { FormItem, FormControl, FormField } from "@/shared/ui/form";
import type { ScheduleFormData } from "../model/schedule-interface";
import { DateTimePicker } from "./date-time-picker";
type ScheduleFormProps = {
form: UseFormReturn<ScheduleFormData>;
scheduleId?: string;
handleSave: (data: ScheduleFormData) => Promise<void>;
handleDelete?: () => Promise<void>;
};
function ScheduleForm({ form, scheduleId, ...props }: ScheduleFormProps) {
const isModifyMode = !!scheduleId;
const [beginDate, setBeginDate] = useState<Date | undefined>(
dayjs(form?.getValues("schdlBgngDt"))?.toDate(),
);
const [endDate, setEndDate] = useState<Date | undefined>(
dayjs(form?.getValues("schdlEndDt"))?.toDate(),
);
const [isAllDay, setIsAllDay] = useState(false);
const [deleteAttachmentIds, setDeleteAttachmentIds] = useState<string[]>([]);
const handleDateTimeChange =
(name: "schdlBgngDt" | "schdlEndDt") => (date?: Date) => {
if (!date) return;
form.setValue(name, dayjs(date).format("YYYY-MM-DD HH:mm:ss"));
setIsAllDay(false);
};
return (
<FormWrapper form={form} isModifyMode={isModifyMode} {...props}>
<div className="card">
<Table variant="secondary">
<colgroup>
<col width="15%" />
<col width="85%" />
</colgroup>
<TableBody>
<TableRow>
<TableHead>제목</TableHead>
<TableCell className="border">
<FormField
control={form.control}
name="schdlTtl"
render={({ field }) => (
<FormItem>
<FormControl>
<Input
{...field}
value={field.value ?? ""}
className="!text-[1.3rem]"
placeholder="일정 제목을 입력하십시오."
/>
</FormControl>
</FormItem>
)}
/>
</TableCell>
</TableRow>
<TableRow>
<TableHead>일정 기간</TableHead>
<TableCell className="border">
<div className="flex items-center gap-4">
<div className="flex items-center gap-2">
<FormField
control={form.control}
name="schdlBgngDt"
render={({ field }) => (
<DateTimePicker
date={beginDate}
classes={{ trigger: "w-auto px-4 justify-start" }}
onDateChange={(date) => {
setBeginDate(date);
handleDateTimeChange("schdlBgngDt")(date);
}}
{...field}
/>
)}
/>
~
<FormField
control={form.control}
name="schdlEndDt"
render={({ field }) => (
<DateTimePicker
date={endDate}
classes={{ trigger: "w-auto px-4 justify-start" }}
onDateChange={(date) => {
setEndDate(date);
handleDateTimeChange("schdlEndDt")(date);
}}
{...field}
/>
)}
/>
</div>
<div className="flex items-center gap-2">
<Checkbox
id="allDay"
checked={isAllDay}
onCheckedChange={(checked) => {
setIsAllDay(checked === true);
if (checked === true) {
const baseDate = form.getValues("schdlBgngDt");
if (baseDate) {
const newStartDate = dayjs(baseDate).format(
"YYYY-MM-DD 00:00:00",
);
const newEndDate = dayjs(baseDate).format(
"YYYY-MM-DD 23:59:59",
);
setBeginDate(dayjs(newStartDate).toDate());
setEndDate(dayjs(newEndDate).toDate());
form.setValue("schdlBgngDt", newStartDate);
form.setValue("schdlEndDt", newEndDate);
}
}
}}
/>
<Label htmlFor="allDay">종일</Label>
</div>
</div>
</TableCell>
</TableRow>
<TableRow>
<TableHead>일정 반복</TableHead>
<TableCell className="border">
<div className="flex items-center gap-4">
<div className="flex items-center gap-2">
<FormField
control={form.control}
name="reptYn"
render={({ field }) => (
<FormItem>
<FormControl>
<div className="mr-2 flex items-center gap-2">
<Checkbox
id="reptY"
checked={field.value === "Y"}
onCheckedChange={(checked) => {
field.onChange(checked ? "Y" : "N");
}}
/>
<Label htmlFor="reptY">반복</Label>
</div>
</FormControl>
</FormItem>
)}
/>
<FormField
control={form.control}
name="reptDto.reptCycleCd"
render={({ field }) => (
<FormItem>
<FormControl>
<CodeSelect
{...field}
upCd="SCHDLRPTCD"
value={field.value ?? ""}
onValueChange={(value) =>
value && field.onChange(value)
}
placeholder="반복 주기 선택"
disabled={form.watch("reptYn") === "N"}
/>
</FormControl>
</FormItem>
)}
/>
<FormField
control={form.control}
name="reptDto.reptEndDt"
render={({ field }) => (
<FormItem>
<FormControl>
<DatePicker
mode="single"
selected={
field.value
? dayjs(field.value).toDate()
: undefined
}
onSelect={(value) =>
value && field.onChange(value)
}
className="w-auto px-4"
placeholder="반복 종료일 선택"
disabled={form.watch("reptYn") === "N"}
/>
</FormControl>
</FormItem>
)}
/>
</div>
</div>
</TableCell>
</TableRow>
<TableRow>
<TableHead>일정 유형</TableHead>
<TableCell className="border">
<FormField
control={form.control}
name="schdlSeCd"
render={({ field }) => (
<FormItem>
<FormControl>
<CodeSelect
{...field}
upCd="SCHDLCLCD"
value={field.value ?? ""}
onValueChange={field.onChange}
/>
</FormControl>
</FormItem>
)}
/>
</TableCell>
</TableRow>
<TableRow>
<TableHead>일정 내용</TableHead>
<TableCell className="border">
<FormField
control={form.control}
name="schdlCn"
render={({ field }) => (
<FormItem>
<FormControl>
<Textarea
{...field}
value={field.value ?? ""}
className="min-h-32 !text-[1.3rem]"
placeholder="일정 내용을 입력하십시오."
/>
</FormControl>
</FormItem>
)}
/>
</TableCell>
</TableRow>
<TableRow>
<TableHead>대상 사이트</TableHead>
<TableCell className="border">
<FormField
control={form.control}
name="commSchdlYn"
render={({ field }) => (
<FormItem>
<FormControl>
<div className="flex items-center gap-2">
<Checkbox
id="commSchdlY"
checked={field.value === "Y"}
onCheckedChange={(checked) => {
field.onChange(checked ? "Y" : "N");
}}
/>
<Label htmlFor="commSchdlY">공용</Label>
</div>
</FormControl>
</FormItem>
)}
/>
</TableCell>
</TableRow>
<TableRow>
<TableHead>첨부 파일</TableHead>
<TableCell className="border">
<GeneralFileUploader
form={form}
deleteAttachmentIds={deleteAttachmentIds}
setDeleteAttachmentIds={setDeleteAttachmentIds}
/>
</TableCell>
</TableRow>
<TableRow>
<TableHead>사용 여부</TableHead>
<TableCell className="border">
<FormField
control={form.control}
name="useYn"
render={({ field }) => (
<FormItem>
<FormControl>
<RadioGroup
className="flex items-center gap-4"
onValueChange={field.onChange}
>
<div className="flex items-center gap-2">
<RadioGroupItem value="Y" id="useY" />
<Label htmlFor="useY">사용</Label>
</div>
<div className="flex items-center gap-2">
<RadioGroupItem value="N" id="useN" />
<Label htmlFor="useN">미사용</Label>
</div>
</RadioGroup>
</FormControl>
</FormItem>
)}
/>
</TableCell>
</TableRow>
</TableBody>
</Table>
</div>
</FormWrapper>
);
}
export { ScheduleForm };
@@ -0,0 +1,63 @@
"use client";
import dayjs from "dayjs";
import { useState } from "react";
import { useRouter } from "next/navigation";
import FullCalendar from "@fullcalendar/react";
import dayGridPlugin from "@fullcalendar/daygrid";
import interactionPlugin, {
type DateClickArg,
} from "@fullcalendar/interaction";
import { useQuery } from "@tanstack/react-query";
import { ENDPOINT, SITE_ID } from "@/shared/config";
import { ScheduleApi } from "../api/schedule-service";
import type { ScheduleParams } from "../model/schedule-interface";
function SchedulePage() {
const router = useRouter();
const [scheduleParams, setScheduleParams] = useState<ScheduleParams>({
siteId: SITE_ID,
schdlBgngYmd: "",
schdlEndYmd: "",
useYn: "Y",
});
const { data } = useQuery({
queryKey: [ENDPOINT.CMS_SERVICE.SCHEDULES, scheduleParams],
queryFn: () => ScheduleApi.getSchedules(scheduleParams),
select: (data) => {
return data.map((item) => ({
title: item.schdlTtl,
start: item.schdlBgngDt,
end: item.schdlEndDt,
}));
},
enabled: !!scheduleParams.schdlBgngYmd && !!scheduleParams.schdlEndYmd,
});
const handleDateClick = (info: DateClickArg) => {
router.push(`/schedule/register?dateStr=${info.dateStr}`);
};
return (
<div className="card card-border">
<div className="p-5">
<FullCalendar
plugins={[dayGridPlugin, interactionPlugin]}
events={data}
locale="ko"
dateClick={handleDateClick}
datesSet={(dateInfo) => {
setScheduleParams({
...scheduleParams,
schdlBgngYmd: dayjs(dateInfo.startStr).format("YYYY-MM-DD"),
schdlEndYmd: dayjs(dateInfo.endStr).format("YYYY-MM-DD"),
});
}}
/>
</div>
</div>
);
}
export { SchedulePage };
+1
View File
@@ -39,6 +39,7 @@ export const ENDPOINT = {
LWPO_CODE: "/cms-service/api/v1/lwpo-cds",
UP_CODE: "/cms-service/api/v1/up-codes",
POPUPS: "/cms-service/api/v1/popups",
SCHEDULES: "/cms-service/api/v1/schdls",
},
BOARD_SERVICE: {
BBS: "/board-service/api/v1/bbs",