251210_01_ENH : 프로젝트 수정, 에디터 구현중
This commit is contained in:
@@ -9,6 +9,7 @@ type BaseProps<T> = {
|
||||
items: T[]
|
||||
searchable?: boolean
|
||||
searchMode?: "filter" | "inputOnly";
|
||||
defaultSearchValue?: string;
|
||||
onSearchValueChange?: (value: string) => void;
|
||||
placeholder?: string
|
||||
widthClassName?: string
|
||||
@@ -16,123 +17,164 @@ type BaseProps<T> = {
|
||||
className?: string
|
||||
getValue?: (item: T) => string
|
||||
getLabel?: (item: T) => string
|
||||
|
||||
/** ✅ 옵션: 원본 item을 option.info에 실어둘지 */
|
||||
withInfo?: boolean
|
||||
}
|
||||
|
||||
type KriMultiSelectProps<T> = BaseProps<T> & {
|
||||
type KriMultiSelectProps<T = unknown> = BaseProps<T> & {
|
||||
value: string[]
|
||||
onChange: (value: string[]) => void
|
||||
/** 최대 선택 개수 제한 (없으면 무제한) */
|
||||
maxCount?: number
|
||||
maxSelected?: number
|
||||
hideSelectAll?: boolean
|
||||
|
||||
/** ✅ withInfo=true일 때만 의미 있게 쓰면 됨 */
|
||||
onItemsChange?: (items: T[]) => void
|
||||
onOptionsChange?: (options: MultiSelectOption<T>[]) => void
|
||||
}
|
||||
|
||||
export function KriMultiSelect<T>({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = "filter",
|
||||
onSearchValueChange,
|
||||
maxCount = 1,
|
||||
maxSelected,
|
||||
hideSelectAll = false,
|
||||
placeholder = 'Select options',
|
||||
widthClassName,
|
||||
heightClassName,
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
}: KriMultiSelectProps<T>) {
|
||||
const extractValue = React.useCallback((item: T) => (getValue ? getValue(item) : String(item)), [getValue])
|
||||
const extractLabel = React.useCallback((item: T) => (getLabel ? getLabel(item) : String(item)), [getLabel])
|
||||
|
||||
const options = React.useMemo<MultiSelectOption[]>(
|
||||
() =>
|
||||
items.map((item) => ({
|
||||
value: extractValue(item),
|
||||
label: extractLabel(item),
|
||||
})),
|
||||
[items, extractValue, extractLabel]
|
||||
export function KriMultiSelect<T = unknown>({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = "filter",
|
||||
defaultSearchValue = "",
|
||||
onSearchValueChange,
|
||||
maxCount = 1,
|
||||
maxSelected,
|
||||
hideSelectAll = false,
|
||||
placeholder = 'Select options',
|
||||
widthClassName,
|
||||
heightClassName,
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
withInfo = false,
|
||||
onItemsChange,
|
||||
onOptionsChange,
|
||||
}: KriMultiSelectProps<T>) {
|
||||
const extractValue = React.useCallback(
|
||||
(item: T) => (getValue ? getValue(item) : String(item)),
|
||||
[getValue]
|
||||
)
|
||||
const extractLabel = React.useCallback(
|
||||
(item: T) => (getLabel ? getLabel(item) : String(item)),
|
||||
[getLabel]
|
||||
)
|
||||
|
||||
const options = React.useMemo<MultiSelectOption<T>[]>(() => {
|
||||
return items.map((item) => ({
|
||||
value: extractValue(item),
|
||||
label: extractLabel(item),
|
||||
...(withInfo ? { info: item } : {}), // ✅ 필요할 때만 info를 실음
|
||||
}))
|
||||
}, [items, extractValue, extractLabel, withInfo])
|
||||
|
||||
return (
|
||||
<div className={cn(widthClassName, heightClassName, "flex-none overflow-hidden")}>
|
||||
<MultiSelect
|
||||
options={options}
|
||||
defaultValue={value}
|
||||
onValueChange={onChange}
|
||||
maxSelected={maxSelected}
|
||||
placeholder={placeholder}
|
||||
className={cn("bg-white content-text-lg", className)}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
maxCount={maxCount}
|
||||
hideSelectAll={hideSelectAll}
|
||||
autoSize
|
||||
singleLine
|
||||
resetOnDefaultValueChange
|
||||
deduplicateOptions
|
||||
/>
|
||||
</div>
|
||||
<div className={cn(widthClassName, heightClassName, "flex-none overflow-hidden")}>
|
||||
<MultiSelect<T>
|
||||
options={options}
|
||||
defaultValue={value}
|
||||
onValueChange={onChange}
|
||||
onOptionChange={onOptionsChange}
|
||||
onInfoChange={onItemsChange}
|
||||
maxSelected={maxSelected}
|
||||
placeholder={placeholder}
|
||||
className={cn("bg-white content-text-lg", className)}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
defaultSearchValue={defaultSearchValue}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
maxCount={maxCount}
|
||||
hideSelectAll={hideSelectAll}
|
||||
autoSize
|
||||
singleLine
|
||||
resetOnDefaultValueChange
|
||||
deduplicateOptions
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
type KriSingleSelectProps<T> = BaseProps<T> & {
|
||||
type KriSingleSelectProps<T = unknown> = BaseProps<T> & {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
onItemChange?: (item: T | null) => void
|
||||
onOptionChange?: (option: MultiSelectOption<T> | null) => void
|
||||
preventDeselect?: boolean;
|
||||
hideOptionCheck?: boolean;
|
||||
}
|
||||
|
||||
export function KriSingleSelect<T>({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = "filter",
|
||||
onSearchValueChange,
|
||||
placeholder = 'Select an option',
|
||||
heightClassName,
|
||||
widthClassName,
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
}: KriSingleSelectProps<T>) {
|
||||
const extractValue = React.useCallback((item: T) => (getValue ? getValue(item) : String(item)), [getValue])
|
||||
const extractLabel = React.useCallback((item: T) => (getLabel ? getLabel(item) : String(item)), [getLabel])
|
||||
|
||||
const options = React.useMemo<MultiSelectOption[]>(
|
||||
() =>
|
||||
items.map((item) => ({
|
||||
value: extractValue(item),
|
||||
label: extractLabel(item),
|
||||
})),
|
||||
[items, extractValue, extractLabel]
|
||||
export function KriSingleSelect<T = unknown>({
|
||||
items,
|
||||
value,
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = "filter",
|
||||
defaultSearchValue = "",
|
||||
onSearchValueChange,
|
||||
placeholder = 'Select an option',
|
||||
heightClassName,
|
||||
widthClassName,
|
||||
className,
|
||||
getValue,
|
||||
getLabel,
|
||||
withInfo = false,
|
||||
onItemChange,
|
||||
onOptionChange,
|
||||
preventDeselect = false,
|
||||
hideOptionCheck = false,
|
||||
}: KriSingleSelectProps<T>) {
|
||||
const extractValue = React.useCallback(
|
||||
(item: T) => (getValue ? getValue(item) : String(item)),
|
||||
[getValue]
|
||||
)
|
||||
const extractLabel = React.useCallback(
|
||||
(item: T) => (getLabel ? getLabel(item) : String(item)),
|
||||
[getLabel]
|
||||
)
|
||||
|
||||
const defaultValue = React.useMemo(() => (value ? [value] : []), [value]);
|
||||
const options = React.useMemo<MultiSelectOption<T>[]>(() => {
|
||||
return items.map((item) => ({
|
||||
value: extractValue(item),
|
||||
label: extractLabel(item),
|
||||
...(withInfo ? { info: item } : {}),
|
||||
}))
|
||||
}, [items, extractValue, extractLabel, withInfo])
|
||||
|
||||
const defaultValue = React.useMemo(() => (value ? [value] : []), [value])
|
||||
|
||||
return (
|
||||
<div className={cn(widthClassName, heightClassName, "flex-none overflow-hidden")}>
|
||||
<MultiSelect
|
||||
options={options}
|
||||
defaultValue={defaultValue}
|
||||
onValueChange={(next) => onChange(next.at(-1) ?? '')}
|
||||
selectionMode="single"
|
||||
maxCount={1}
|
||||
maxSelected={1}
|
||||
placeholder={placeholder}
|
||||
className={cn("bg-white content-text-lg", className)}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
hideSelectAll
|
||||
autoSize
|
||||
singleLine
|
||||
closeOnSelect
|
||||
resetOnDefaultValueChange
|
||||
deduplicateOptions
|
||||
/>
|
||||
</div>
|
||||
<div className={cn(widthClassName, heightClassName, "flex-none overflow-hidden")}>
|
||||
<MultiSelect<T>
|
||||
options={options}
|
||||
defaultValue={defaultValue}
|
||||
onValueChange={(next) => onChange(next[0] ?? '')}
|
||||
onOptionChange={(opts) => {
|
||||
const opt = opts[0] ?? null
|
||||
onOptionChange?.(opt)
|
||||
onItemChange?.((withInfo ? (opt?.info ?? null) : null))
|
||||
}}
|
||||
selectionMode="single"
|
||||
maxCount={1}
|
||||
maxSelected={1}
|
||||
placeholder={placeholder}
|
||||
className={cn("bg-white content-text-lg", className)}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
defaultSearchValue={defaultSearchValue}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
preventDeselect={preventDeselect}
|
||||
hideOptionCheck={hideOptionCheck}
|
||||
hideSelectAll
|
||||
autoSize
|
||||
singleLine
|
||||
closeOnSelect
|
||||
resetOnDefaultValueChange
|
||||
deduplicateOptions
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
import { useAtomValue } from "jotai";
|
||||
import { loadingAtom } from "@/store/jotai/loading";
|
||||
|
||||
export function LoadingOverlay() {
|
||||
export function LoadingOverlay({ force = false }: { force?: boolean }) {
|
||||
const isLoading = useAtomValue(loadingAtom);
|
||||
|
||||
if (!isLoading) return null;
|
||||
if (!force && !isLoading) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[9999] bg-black/70 flex items-center justify-center">
|
||||
|
||||
@@ -30,6 +30,7 @@ import { usePagination } from './hooks/usePagination'
|
||||
import { DataTableProps, DataTableColumn } from './DataTable.type'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
import {usePreventClickOnDrag} from "@/components/data-table/hooks/usePreventClickOnDrag";
|
||||
|
||||
export function DataTable<TData>({
|
||||
columns,
|
||||
@@ -42,8 +43,8 @@ export function DataTable<TData>({
|
||||
onPaginationChange: onServerPaginationChange,
|
||||
onSortingChange: onServerSortingChange,
|
||||
selectMode = 'none',
|
||||
onRowClick,
|
||||
onRowSelectionChange,
|
||||
enableRowClickSelection = false,
|
||||
defaultPageSize = 10,
|
||||
pageSizeOptions = [5, 10, 25, 50],
|
||||
paginationItemsToDisplay = 5
|
||||
@@ -60,6 +61,10 @@ export function DataTable<TData>({
|
||||
// Row selection state
|
||||
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
|
||||
|
||||
const drag = usePreventClickOnDrag(6);
|
||||
|
||||
const isNotSelection = !['none', 'click-event'].includes(selectMode);
|
||||
|
||||
// 서버 페이지네이션일 때 부모에게 알림
|
||||
useEffect(() => {
|
||||
if (!isClient && onServerPaginationChange) {
|
||||
@@ -76,7 +81,7 @@ export function DataTable<TData>({
|
||||
|
||||
// Row selection 변경 시 부모에게 알림
|
||||
useEffect(() => {
|
||||
if (selectMode !== 'none' && onRowSelectionChange) {
|
||||
if (isNotSelection && onRowSelectionChange) {
|
||||
const selectedRows = table
|
||||
.getSelectedRowModel()
|
||||
.rows.map(row => row.original)
|
||||
@@ -86,7 +91,7 @@ export function DataTable<TData>({
|
||||
|
||||
// selectMode에 따라 select column 추가
|
||||
const enhancedColumns: DataTableColumn<TData, any>[] = [
|
||||
...(selectMode !== 'none'
|
||||
...(isNotSelection
|
||||
? [
|
||||
{
|
||||
id: 'select',
|
||||
@@ -125,13 +130,23 @@ export function DataTable<TData>({
|
||||
|
||||
// Row 클릭 핸들러
|
||||
const handleRowClick = (row: any) => {
|
||||
if (!enableRowClickSelection || selectMode === 'none') return
|
||||
switch (selectMode) {
|
||||
case 'none':
|
||||
return
|
||||
|
||||
if (selectMode === 'single') {
|
||||
table.resetRowSelection()
|
||||
row.toggleSelected(true)
|
||||
} else {
|
||||
row.toggleSelected(!row.getIsSelected())
|
||||
case 'click-event':
|
||||
if (!onRowClick) return
|
||||
onRowClick(row.original)
|
||||
return
|
||||
|
||||
case 'single':
|
||||
table.resetRowSelection()
|
||||
row.toggleSelected(true)
|
||||
return
|
||||
|
||||
default: // 'multi' 등
|
||||
row.toggleSelected(!row.getIsSelected())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +159,7 @@ export function DataTable<TData>({
|
||||
pagination,
|
||||
rowSelection
|
||||
},
|
||||
enableRowSelection: selectMode !== 'none',
|
||||
enableRowSelection: isNotSelection,
|
||||
onRowSelectionChange: setRowSelection,
|
||||
onSortingChange: setSorting,
|
||||
onPaginationChange: setPagination,
|
||||
@@ -218,11 +233,15 @@ export function DataTable<TData>({
|
||||
<TableRow
|
||||
key={row.id}
|
||||
data-state={row.getIsSelected() && 'selected'}
|
||||
onClick={() => handleRowClick(row)}
|
||||
onPointerDown={drag.onPointerDown}
|
||||
onPointerMove={drag.onPointerMove}
|
||||
onPointerUp={drag.onPointerUp}
|
||||
onPointerCancel={drag.onPointerCancel}
|
||||
onClick={drag.wrapClick(() => handleRowClick(row))}
|
||||
className={cn(
|
||||
'content-text-base',
|
||||
'[&>td]:py-0 [&>td]:px-2',
|
||||
enableRowClickSelection && selectMode !== 'none' && 'cursor-pointer',
|
||||
selectMode !== 'none' && 'cursor-pointer',
|
||||
'data-[state=selected]:bg-slate-100 data-[state=selected]:font-semibold',
|
||||
shouldHighlight && 'bg-emerald-50',
|
||||
)}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ColumnDef, PaginationState, SortingState } from '@tanstack/react-table'
|
||||
|
||||
export type SelectMode = 'none' | 'single' | 'multi'
|
||||
export type SelectMode = 'none' | 'click-event' | 'single' | 'multi'
|
||||
|
||||
export type DataTableColumn<TData, TValue = unknown> = ColumnDef<TData, TValue> & {
|
||||
enableSorting?: boolean // 정렬 가능 여부 (기본값: false)
|
||||
@@ -33,10 +33,10 @@ export interface DataTableProps<TData> {
|
||||
onPaginationChange?: (pagination: PaginationState) => void
|
||||
onSortingChange?: (sorting: SortingState) => void
|
||||
|
||||
// 선택 모드
|
||||
selectMode?: SelectMode // 'none' | 'single' | 'multi' (기본값: 'none')
|
||||
// 선택 모드
|
||||
selectMode?: SelectMode // 'none' | 'click-event' | 'single' | 'multi' (기본값: 'none')
|
||||
onRowClick?: (selectedRows: TData) => void
|
||||
onRowSelectionChange?: (selectedRows: TData[]) => void
|
||||
enableRowClickSelection?: boolean // row 클릭 시 select 여부 (기본값: false)
|
||||
|
||||
// 페이지네이션 설정
|
||||
defaultPageSize?: number
|
||||
|
||||
48
src/components/data-table/hooks/usePreventClickOnDrag.ts
Normal file
48
src/components/data-table/hooks/usePreventClickOnDrag.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import * as React from "react";
|
||||
|
||||
export const usePreventClickOnDrag = (thresholdPx = 6) => {
|
||||
const s = React.useRef({ x: 0, y: 0, dragging: false });
|
||||
|
||||
const onPointerDown = React.useCallback((e: React.PointerEvent) => {
|
||||
// 좌클릭만
|
||||
if (e.button !== 0) return;
|
||||
s.current.x = e.clientX;
|
||||
s.current.y = e.clientY;
|
||||
s.current.dragging = false;
|
||||
}, []);
|
||||
|
||||
const onPointerMove = React.useCallback(
|
||||
(e: React.PointerEvent) => {
|
||||
// 누르고 있을 때만
|
||||
if (e.buttons === 0) return;
|
||||
|
||||
const dx = e.clientX - s.current.x;
|
||||
const dy = e.clientY - s.current.y;
|
||||
|
||||
if (dx * dx + dy * dy >= thresholdPx * thresholdPx) {
|
||||
s.current.dragging = true;
|
||||
}
|
||||
},
|
||||
[thresholdPx]
|
||||
);
|
||||
|
||||
const onPointerUp = React.useCallback(() => {
|
||||
// click은 pointerup 다음에 발생하므로 "다음 tick"에 false로 복구
|
||||
setTimeout(() => {
|
||||
s.current.dragging = false;
|
||||
}, 0);
|
||||
}, []);
|
||||
|
||||
const wrapClick =
|
||||
(fn: () => void) =>
|
||||
(e: React.MouseEvent) => {
|
||||
if (s.current.dragging) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
fn();
|
||||
};
|
||||
|
||||
return { onPointerDown, onPointerMove, onPointerUp, onPointerCancel: onPointerUp, wrapClick };
|
||||
}
|
||||
269
src/components/dialog/ProjectCreateDialog.tsx
Normal file
269
src/components/dialog/ProjectCreateDialog.tsx
Normal file
@@ -0,0 +1,269 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useEffect } from 'react'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle
|
||||
} from "@/components/ui/dialog";
|
||||
import {Label} from "@/components/ui/label";
|
||||
import {Input} from "@/components/ui/input";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {KriSingleSelect} from "@/components/common/KriAutoComplete";
|
||||
import {useDialog} from "@/hooks/useDialog";
|
||||
import type {DialogId} from "@/store/jotai/dialog";
|
||||
import {NONE_HTTP_ERROR, UNKNOWN_HTTP_ERROR} from "@/const/commonConst";
|
||||
import {apiError} from "@/lib/http-util";
|
||||
import {IntranetProjectSearchResponse, ProjectCreateRequest} from "@/types/project";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {PROJECT_NAME_REGEX} from "@/const/projectConst";
|
||||
import {FW_TEAM, USER_NAME_REGEX} from "@/const/userConst";
|
||||
import {MultiSelectOption} from "@/components/ui/multi-select";
|
||||
import {ItrntUserInfo} from "@/types/user";
|
||||
|
||||
export type ProjectCreateDialogProps = {
|
||||
/** Jotai로 관리할 다이얼로그 ID (기본값: 'userUpsertDialog') */
|
||||
dialogId?: DialogId
|
||||
|
||||
/** 필요하면 여전히 외부에서 open 제어도 가능하게 */
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
users:ItrntUserInfo[]
|
||||
ownerFw: string;
|
||||
onSubmit: (data: ProjectCreateRequest) => void | Promise<void>
|
||||
}
|
||||
|
||||
|
||||
|
||||
const ProjectCreateDialog = ({
|
||||
dialogId = 'projectCreateDialog',
|
||||
open,
|
||||
onOpenChange,
|
||||
users,
|
||||
ownerFw,
|
||||
onSubmit,
|
||||
}:ProjectCreateDialogProps) => {
|
||||
const defaultProjectInfo:ProjectCreateRequest = {
|
||||
prjctName: "",
|
||||
itrntPrjctCd: "",
|
||||
ownerDept: "",
|
||||
ownerFw: ownerFw,
|
||||
}
|
||||
const { isDialogOpen, showDialog, hideDialog } = useDialog();
|
||||
const [deptArray, setDeptArray] = useState<string[]>([]);
|
||||
const [fwArray, setFwArray] = useState<MultiSelectOption[]>([]);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [formData, setFormData] = useState<ProjectCreateRequest>(defaultProjectInfo);
|
||||
|
||||
const [itrntKeyword, setItrntKeyword] = useState('');
|
||||
const debouncedKeyword = useDebouncedValue(itrntKeyword, 500);
|
||||
const [itrntPrjctArray, setItrntPrjctArray] = useState<IntranetProjectSearchResponse[]>([]);
|
||||
|
||||
// 🔹 실제로 Dialog에 넘길 open 값 (외부 open 있으면 우선)
|
||||
const resolvedOpen = open ?? isDialogOpen(dialogId);
|
||||
|
||||
// 🔹 실제 onOpenChange 핸들러 (외부 콜백 + jotai 둘 다 처리)
|
||||
const handleOpenChange = (nextOpen: boolean) => {
|
||||
// 1) 외부에서 넘겨준 onOpenChange 먼저 호출
|
||||
onOpenChange?.(nextOpen);
|
||||
|
||||
// 2) jotai 전역 상태도 함께 업데이트
|
||||
if (nextOpen) {
|
||||
showDialog(dialogId);
|
||||
setItrntKeyword("");
|
||||
} else {
|
||||
hideDialog(dialogId);
|
||||
}
|
||||
}
|
||||
|
||||
const handleInputChange = (field: keyof ProjectCreateRequest, value: any) => {
|
||||
setFormData((prev) => {
|
||||
const next = { ...prev, [field]: value } as ProjectCreateRequest;
|
||||
|
||||
if (field === "itrntPrjctCd") {
|
||||
const selected = itrntPrjctArray.find((p) => p.childSn === value);
|
||||
if (selected){
|
||||
next.ownerDept = selected.researchTeam;
|
||||
next.prjctName = selected.title;
|
||||
}
|
||||
}
|
||||
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if(!formData.itrntPrjctCd.trim()){
|
||||
alert("인트라넷 프로젝트를 선택해 주세요");
|
||||
return;
|
||||
}
|
||||
if (!formData.prjctName.trim()) {
|
||||
alert('프로젝트 명을 입력해 주세요');
|
||||
return;
|
||||
}
|
||||
if (!PROJECT_NAME_REGEX.test(formData.prjctName)) {
|
||||
alert("프로젝트명에 허용되지 않는 문자가 포함되어 있습니다");
|
||||
return;
|
||||
}
|
||||
if(!formData.ownerDept.trim()){
|
||||
alert('담당 그룹을 입력해 주세요');
|
||||
return;
|
||||
}
|
||||
if(!USER_NAME_REGEX.test(formData.ownerDept)){
|
||||
alert('담당 그룹이 올바르지 않습니다.');
|
||||
return;
|
||||
}
|
||||
if(!formData.ownerFw.trim()){
|
||||
alert('담당 SV를 입력해 주세요');
|
||||
return;
|
||||
}
|
||||
if(!USER_NAME_REGEX.test(formData.ownerDept)){
|
||||
alert('담당 SV가 올바르지 않습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
await onSubmit(formData as ProjectCreateRequest);
|
||||
handleOpenChange(false);
|
||||
} catch (e) {
|
||||
const err = apiError(e);
|
||||
if(err.code !== NONE_HTTP_ERROR && err.code !== UNKNOWN_HTTP_ERROR){
|
||||
alert(err.message);
|
||||
}
|
||||
else{
|
||||
alert('저장에 실패했습니다.');
|
||||
}
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
}
|
||||
|
||||
const searchItrntPrjct = async (keyword:string): Promise<void> => {
|
||||
const res = await nextApi.get<IntranetProjectSearchResponse[]>(
|
||||
"/intranet/project",
|
||||
{ query: keyword ? { keyword } : {} }
|
||||
);
|
||||
|
||||
setItrntPrjctArray(res);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const keyword = debouncedKeyword.trim();
|
||||
searchItrntPrjct(keyword).then();
|
||||
}, [debouncedKeyword]);
|
||||
|
||||
useEffect(() => {
|
||||
setFormData(defaultProjectInfo);
|
||||
}, [resolvedOpen])
|
||||
|
||||
useEffect(() => {
|
||||
let userTeams = Array.from(new Set(users.map(u => u.userTeam)));
|
||||
if(!userTeams.includes("T900")){ //TFT
|
||||
userTeams.push("T900");
|
||||
}
|
||||
userTeams = userTeams.sort((a, b) => a.localeCompare(b, "ko"));
|
||||
setDeptArray(userTeams);
|
||||
|
||||
const userOptions: MultiSelectOption[] = users
|
||||
.filter(u => u.userId == ownerFw || u.userTeam == FW_TEAM)
|
||||
.map(u => ({
|
||||
value: u.userId,
|
||||
label: u.userNm,
|
||||
}));
|
||||
setFwArray(userOptions);
|
||||
}, [users]);
|
||||
|
||||
return (
|
||||
<Dialog open={resolvedOpen} onOpenChange={handleOpenChange}>
|
||||
<DialogContent className="sm:max-w-[500px] content-text-sm">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="content-text-sxl">
|
||||
프로젝트 생성
|
||||
</DialogTitle>
|
||||
<DialogDescription>프로젝트 생성에 필요한 기본정보를 입력해주세요.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-6 py-4">
|
||||
<div className="grid gap-2">
|
||||
<Label>
|
||||
인트라넷 프로젝트<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<KriSingleSelect
|
||||
items={itrntPrjctArray}
|
||||
value={String(formData.itrntPrjctCd)}
|
||||
onChange={(e) => handleInputChange('itrntPrjctCd', e)}
|
||||
getLabel={(item) => `[${item.childSn}] ${item.title}`}
|
||||
getValue={(item) => item.childSn}
|
||||
searchMode={"inputOnly"}
|
||||
onSearchValueChange={setItrntKeyword}
|
||||
placeholder="인트라넷 프로젝트"
|
||||
widthClassName="w-full"
|
||||
heightClassName="h-9"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="prjctName">
|
||||
프로젝트 명<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="prjctName"
|
||||
placeholder="프로젝트명을 입력하세요"
|
||||
value={formData.prjctName}
|
||||
onChange={(e) => handleInputChange('prjctName', e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="ownerDept">
|
||||
담당 그룹<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<KriSingleSelect
|
||||
items={deptArray}
|
||||
value={formData.ownerDept || ''}
|
||||
onChange={(value) => handleInputChange('ownerDept', value)}
|
||||
placeholder="담당 그룹을 선택하세요"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="ownerFw">
|
||||
담당 실사<span className="text-red-500 ml-1">*</span>
|
||||
</Label>
|
||||
<KriSingleSelect
|
||||
items={fwArray}
|
||||
value={formData.ownerFw || ''}
|
||||
onChange={(value) => handleInputChange('ownerFw', value)}
|
||||
getValue={(item) => item.value}
|
||||
getLabel={(item) => item.label}
|
||||
placeholder="담당 실사를 선택하세요"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => handleOpenChange(false)}
|
||||
>
|
||||
취소
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
onClick={handleSubmit}
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
생성
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProjectCreateDialog
|
||||
325
src/components/dialog/ResultCodeDialog.tsx
Normal file
325
src/components/dialog/ResultCodeDialog.tsx
Normal file
@@ -0,0 +1,325 @@
|
||||
'use client'
|
||||
|
||||
import { useMemo, useState } from 'react'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import {Trash2, Plus, Download, Search, XIcon} from 'lucide-react'
|
||||
|
||||
export type ResultCode = {
|
||||
code: string
|
||||
label: string
|
||||
}
|
||||
|
||||
type Project = {
|
||||
prjctCd: string
|
||||
prjctName: string
|
||||
resultCodes: ResultCode[]
|
||||
}
|
||||
|
||||
type ResultCodeDialogProps = {
|
||||
open?: boolean
|
||||
onOpenChange?: (open: boolean) => void
|
||||
onSave?: (codes: ResultCode[]) => void
|
||||
}
|
||||
|
||||
const ResultCodeDialog = ({ open, onOpenChange, onSave }: ResultCodeDialogProps) => {
|
||||
const [importMode, setImportMode] = useState(false)
|
||||
const [selectedProject, setSelectedProject] = useState<string>('')
|
||||
|
||||
const [resultCodes, setResultCodes] = useState<ResultCode[]>([
|
||||
{ code: '0', label: '컨택 성공' },
|
||||
{ code: '1', label: '통화 예약' },
|
||||
{ code: '2', label: '비수신' },
|
||||
{ code: '3', label: '부재' },
|
||||
{ code: '4', label: '휴가' },
|
||||
{ code: '5', label: '출장' },
|
||||
{ code: '6', label: '단순 거절' },
|
||||
{ code: '7', label: '강력 거절' },
|
||||
{ code: '8', label: '그런 사람 아님' },
|
||||
{ code: '9', label: '메일 발송' },
|
||||
{ code: '10', label: '독려' },
|
||||
{ code: '11', label: '퇴사' },
|
||||
{ code: '12', label: '기타' },
|
||||
{ code: '13', label: '조사 대상 아님' },
|
||||
{ code: '14', label: '수신 거부' },
|
||||
])
|
||||
|
||||
// 샘플 프로젝트 목록 (실제로는 API에서 가져옴)
|
||||
const projects: Project[] = [
|
||||
{
|
||||
prjctCd: '250701yd',
|
||||
prjctName: '250701yd',
|
||||
resultCodes: [
|
||||
{ code: '0', label: '완료' },
|
||||
{ code: '1', label: '거절' },
|
||||
{ code: '2', label: '진행중' },
|
||||
],
|
||||
},
|
||||
{
|
||||
prjctCd: '1509013',
|
||||
prjctName: '1509013_J2307KJC_KFB_저기 1차 카카오톡 AUTOAGI_#01250Group',
|
||||
resultCodes: [
|
||||
{ code: '0', label: '성공' },
|
||||
{ code: '1', label: '실패' },
|
||||
{ code: '2', label: '보류' },
|
||||
],
|
||||
},
|
||||
{
|
||||
prjctCd: '1503013',
|
||||
prjctName: '1503013_J2307KJC_KFB_저기 1차 카카오톡 AUTOAGI_그룹01테스트0',
|
||||
resultCodes: [
|
||||
{ code: '0', label: '승인' },
|
||||
{ code: '1', label: '반려' },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const [projectSearch, setProjectSearch] = useState('')
|
||||
const filteredProjects = useMemo(() => {
|
||||
const q = projectSearch.trim().toLowerCase()
|
||||
if (!q) return projects
|
||||
return projects.filter(p =>
|
||||
`${p.prjctCd} ${p.prjctName}`.toLowerCase().includes(q)
|
||||
)
|
||||
}, [projectSearch])
|
||||
|
||||
const selectedProjectData = useMemo(
|
||||
() => projects.find(p => p.prjctCd === selectedProject),
|
||||
[selectedProject]
|
||||
)
|
||||
|
||||
const handleAddCode = () => {
|
||||
setResultCodes(prev => [...prev, { code: String(prev.length), label: '' }])
|
||||
}
|
||||
|
||||
const handleDeleteCode = (index: number) => {
|
||||
setResultCodes(prev => prev.filter((_, i) => i !== index))
|
||||
}
|
||||
|
||||
const handleCodeChange = (index: number, field: keyof ResultCode, value: string) => {
|
||||
setResultCodes(prev => {
|
||||
const next = [...prev]
|
||||
next[index] = { ...next[index], [field]: value }
|
||||
return next
|
||||
})
|
||||
}
|
||||
|
||||
const handleImportClick = () => {
|
||||
setImportMode(true)
|
||||
}
|
||||
|
||||
const handleImportApply = () => {
|
||||
if (selectedProjectData) {
|
||||
setResultCodes(selectedProjectData.resultCodes)
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
}
|
||||
|
||||
const handleImportCancel = () => {
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
|
||||
const handleSave = () => {
|
||||
onSave?.(resultCodes)
|
||||
onOpenChange?.(false)
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
|
||||
const handleClose = () => {
|
||||
onOpenChange?.(false)
|
||||
setImportMode(false)
|
||||
setSelectedProject('')
|
||||
setProjectSearch('')
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
{/* ✅ importMode일 때 더 넓게(그리고 애니메이션으로 부드럽게) */}
|
||||
<DialogContent
|
||||
className={[
|
||||
'p-0 overflow-hidden',
|
||||
'transition-all duration-200',
|
||||
importMode ? 'sm:max-w-6xl' : 'sm:max-w-3xl',
|
||||
'w-[calc(100vw-2rem)]',
|
||||
'max-h-[85vh]',
|
||||
'gap-2',
|
||||
].join(' ')}
|
||||
>
|
||||
<DialogHeader className="px-6 pt-6 pb-4 border-b">
|
||||
<DialogTitle className="flex items-center justify-between gap-3">
|
||||
<span>결과 코드 설정</span>
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
{/* 상단 버튼 영역 */}
|
||||
<div className="px-6 pt-1 pb-3 border-b bg-white flex justify-end">
|
||||
{!importMode ? (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={handleImportClick}
|
||||
className="h-9 px-3 gap-2"
|
||||
>
|
||||
<Download className="w-4 h-4" />
|
||||
가져오기
|
||||
</Button>
|
||||
) : (
|
||||
<div className="flex items-center gap-2 w-130">
|
||||
<div className="relative flex-1">
|
||||
<Search className="w-4 h-4 text-gray-400 absolute left-3 top-1/2 -translate-y-1/2" />
|
||||
<Input
|
||||
value={projectSearch}
|
||||
onChange={(e) => setProjectSearch(e.target.value)}
|
||||
placeholder="프로젝트 코드/이름 검색..."
|
||||
className="h-9 pl-9"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 본문 */}
|
||||
<div className={importMode ? 'grid grid-cols-1 lg:grid-cols-2' : 'block'}>
|
||||
{/* 왼쪽: 결과 코드 */}
|
||||
<div className="p-6">
|
||||
<div className="rounded-lg border bg-white overflow-hidden">
|
||||
<div className="px-4 py-3 border-b bg-gray-50 flex items-center justify-between">
|
||||
<div className="font-semibold text-sm text-gray-900">결과 코드 목록</div>
|
||||
{!importMode && (
|
||||
<Button onClick={handleAddCode} variant="outline" size="sm" className="gap-2">
|
||||
<Plus className="w-4 h-4" />
|
||||
추가
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="max-h-[420px] overflow-y-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-white border-b">
|
||||
<tr className="text-gray-600">
|
||||
<th className="px-4 py-2 text-left w-36">코드</th>
|
||||
<th className="px-4 py-2 text-left">레이블</th>
|
||||
<th className="px-2 py-2 w-12" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y">
|
||||
{resultCodes.map((code, index) => (
|
||||
<tr key={index} className="hover:bg-gray-50">
|
||||
<td className="px-4 py-2 align-middle">
|
||||
<Input
|
||||
value={code.code}
|
||||
onChange={(e) => handleCodeChange(index, 'code', e.target.value)}
|
||||
className="h-9"
|
||||
disabled={importMode}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-4 py-2 align-middle">
|
||||
<Input
|
||||
value={code.label}
|
||||
onChange={(e) => handleCodeChange(index, 'label', e.target.value)}
|
||||
className="h-9"
|
||||
disabled={importMode}
|
||||
/>
|
||||
</td>
|
||||
<td className="px-2 py-2 align-middle">
|
||||
{!importMode && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => handleDeleteCode(index)}
|
||||
aria-label="delete"
|
||||
>
|
||||
<Trash2 className="w-4 h-4 text-red-600" />
|
||||
</Button>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{!importMode && (
|
||||
<div className="px-4 py-3 border-t bg-gray-50 text-xs text-gray-500">
|
||||
Tip: 코드 값은 중복되지 않게 유지해주세요.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 오른쪽: importMode일 때만 */}
|
||||
{importMode && (
|
||||
<div className="p-6 border-t lg:border-t-0 lg:border-l bg-white">
|
||||
{/* 미리보기 */}
|
||||
<div className="rounded-lg border bg-white overflow-hidden">
|
||||
<div className="px-4 py-3 border-b bg-gray-50 flex items-center justify-between">
|
||||
<div className="font-semibold text-sm text-gray-900">미리보기</div>
|
||||
</div>
|
||||
|
||||
<div className="max-h-[180px] overflow-y-auto">
|
||||
{selectedProjectData ? (
|
||||
<table className="w-full text-sm">
|
||||
<thead className="sticky top-0 bg-white border-b">
|
||||
<tr className="text-gray-600">
|
||||
<th className="px-4 py-2 text-left w-32">코드</th>
|
||||
<th className="px-4 py-2 text-left">레이블</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y">
|
||||
{selectedProjectData.resultCodes.map((code, idx) => (
|
||||
<tr key={idx}>
|
||||
<td className="px-4 py-2">{code.code}</td>
|
||||
<td className="px-4 py-2">{code.label}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
) : (
|
||||
<div className="p-4 text-sm text-gray-500">프로젝트를 선택하세요.</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<DialogFooter className="px-6 py-4 border-t bg-white">
|
||||
{importMode ? (
|
||||
<>
|
||||
<Button variant="outline" onClick={handleImportCancel}>
|
||||
취소
|
||||
</Button>
|
||||
<Button onClick={handleImportApply} disabled={!selectedProject} className="gap-2">
|
||||
<Download className="w-4 h-4" />
|
||||
가져오기 적용
|
||||
</Button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Button variant="outline" onClick={handleClose}>
|
||||
취소
|
||||
</Button>
|
||||
<Button onClick={handleSave}>
|
||||
저장
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
|
||||
export default ResultCodeDialog
|
||||
@@ -18,9 +18,10 @@ import { UserInfoSaveRequest } from '@/types/user'
|
||||
import KriPassword from "@/components/common/KriPassword";
|
||||
import {KriSelect, KriSelectItem} from "@/components/common/KriSelect";
|
||||
import {DataVerification} from "@/types/common";
|
||||
import commonConst from "@/config/commonConst";
|
||||
import {apiError} from "@/lib/http-util";
|
||||
import {KriSingleSelect} from "@/components/common/KriAutoComplete";
|
||||
import {USER_NAME_REGEX} from "@/const/userConst";
|
||||
import {NONE_HTTP_ERROR, UNKNOWN_HTTP_ERROR} from "@/const/commonConst";
|
||||
|
||||
export type UserUpsertDialogProps = {
|
||||
/** Jotai로 관리할 다이얼로그 ID (기본값: 'userUpsertDialog') */
|
||||
@@ -151,19 +152,20 @@ const UserUpsertDialog = ({
|
||||
alert('이름을 입력해주세요.');
|
||||
return;
|
||||
}
|
||||
if(!commonConst.nameRegex.test(formData.userName)){
|
||||
if(!USER_NAME_REGEX.test(formData.userName)){
|
||||
alert('올바르지 않은 이름입니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true)
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
await onSubmit(formData as UserInfoSaveRequest);
|
||||
handleOpenChange(false);
|
||||
} catch (e) {
|
||||
const err = apiError(e);
|
||||
console.error(err.status, err.code, err.message);
|
||||
if(err.code !== commonConst.noneHttpError && err.code !== commonConst.unknownHttpError){
|
||||
if(err.code !== NONE_HTTP_ERROR && err.code !== UNKNOWN_HTTP_ERROR){
|
||||
alert(err.message);
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -5,7 +5,7 @@ interface BodyTitleProps {
|
||||
const BodyTitle = ({titleText}:BodyTitleProps) => {
|
||||
return (
|
||||
<div className="flex justify-between items-center">
|
||||
<h1 className="font-bold content-text-4xl">{titleText}</h1>
|
||||
<h1 className="font-bold content-text-2xl">{titleText}</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ interface HeaderProps {
|
||||
menuOpen: boolean;
|
||||
activeTopId: string;
|
||||
fontSize: number;
|
||||
handleIsProjectMenu: (isProjectMenu: boolean) => void;
|
||||
onToggleMenu: () => void;
|
||||
onNavigate: (path: string) => void;
|
||||
decreaseFontSize: () => void;
|
||||
@@ -25,12 +24,11 @@ export const Header = ({
|
||||
menuOpen,
|
||||
activeTopId,
|
||||
fontSize,
|
||||
handleIsProjectMenu,
|
||||
onToggleMenu,
|
||||
onNavigate,
|
||||
decreaseFontSize,
|
||||
increaseFontSize,
|
||||
}: HeaderProps) => {
|
||||
}: HeaderProps) => {
|
||||
const { auth } = useAuth();
|
||||
const [userInfo, setUserInfo] = useState<LoginUser|undefined>(undefined);
|
||||
|
||||
@@ -38,6 +36,9 @@ export const Header = ({
|
||||
if(auth.user){
|
||||
setUserInfo(auth.user);
|
||||
}
|
||||
else{
|
||||
onNavigate("/logout")
|
||||
}
|
||||
}, [auth])
|
||||
|
||||
return (
|
||||
@@ -79,10 +80,7 @@ export const Header = ({
|
||||
<Button
|
||||
key={m.id}
|
||||
variant={activeTopId === m.id ? "default" : "ghost"}
|
||||
onClick={() => {
|
||||
handleIsProjectMenu(m.id === "project");
|
||||
onNavigate(m.path);
|
||||
}}
|
||||
onClick={() => onNavigate(m.path)}
|
||||
>
|
||||
{m.label}
|
||||
</Button>
|
||||
|
||||
@@ -6,7 +6,10 @@ import { Header } from "@/components/layout/Header";
|
||||
import { Sidebar } from "@/components/layout/Sidebar";
|
||||
import {useFontSize} from "@/hooks/useFontSize";
|
||||
import {projectSideMenus, manageSideMenus, topMenus} from "@/config/menu.data";
|
||||
import commonConst from "@/config/commonConst";
|
||||
import ProjectTitle from "@/components/layout/ProjectTitle";
|
||||
import {cn} from "@/lib/utils";
|
||||
import {FONT_SIZE} from "@/const/commonConst";
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
|
||||
type MainLayoutProps = {
|
||||
children: ReactNode;
|
||||
@@ -17,13 +20,15 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
|
||||
const [isProjectMenu, setIsProjectMenu] = useState(false);
|
||||
const { selectedProject } = useSelectedProject();
|
||||
const [menuOpen, setMenuOpen] = useState(true);
|
||||
const [fontSize, setFontSize] = useFontSize(initialFontSize, { hydrateFromCookie: false });
|
||||
|
||||
const isMain = pathname === "/";
|
||||
const isProjectMenu = !pathname.startsWith("/manage");
|
||||
const isViewProjectTitle = !isMain && isProjectMenu && !pathname.startsWith("/project/info")
|
||||
const activeTop = topMenus.find((m) => m.match?.(pathname)) ?? topMenus[0];
|
||||
const sideMenus = pathname.startsWith("/manage") ? manageSideMenus : projectSideMenus;
|
||||
const sideMenus = isProjectMenu ? projectSideMenus : manageSideMenus;
|
||||
|
||||
// 2단 메뉴 open 상태
|
||||
const [openMenus, setOpenMenus] = useState<Record<string, boolean>>(() => {
|
||||
@@ -43,10 +48,6 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
return initial;
|
||||
});
|
||||
|
||||
const handleIsProjectMenu = (isProject: boolean) => {
|
||||
setIsProjectMenu(isProject);
|
||||
}
|
||||
|
||||
const movePage = (path: string) => {
|
||||
router.push(path);
|
||||
};
|
||||
@@ -56,11 +57,11 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
};
|
||||
|
||||
const decreaseFontSize = () =>{
|
||||
setFontSize(Math.max(commonConst.fontSizeMin, fontSize - 2));
|
||||
setFontSize(Math.max(FONT_SIZE.MIN, fontSize - 2));
|
||||
}
|
||||
|
||||
const increaseFontSize = () =>{
|
||||
setFontSize(Math.min(commonConst.fontSizeMax, fontSize + 2));
|
||||
setFontSize(Math.min(FONT_SIZE.MAX, fontSize + 2));
|
||||
}
|
||||
|
||||
// CSS 변수 동기화
|
||||
@@ -72,15 +73,25 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
);
|
||||
}, [fontSize]);
|
||||
|
||||
useEffect(() => {
|
||||
if(!isMain && isProjectMenu && !selectedProject){
|
||||
alert("옳지 않은 접근입니다.");
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
<div
|
||||
className={cn(
|
||||
"bg-gray-50 flex flex-col",
|
||||
isMain ? "min-h-screen" : "h-screen overflow-hidden" // ✅ 메인 제외: 바깥 스크롤 잠금
|
||||
)}
|
||||
>
|
||||
{/* 헤더 - 고정 폰트 크기 */}
|
||||
<Header
|
||||
isMain={isMain}
|
||||
menuOpen={menuOpen}
|
||||
activeTopId={activeTop.id}
|
||||
fontSize={fontSize}
|
||||
handleIsProjectMenu={handleIsProjectMenu}
|
||||
onToggleMenu={() => setMenuOpen((prev) => !prev)}
|
||||
onNavigate={movePage}
|
||||
decreaseFontSize={decreaseFontSize}
|
||||
@@ -88,7 +99,7 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
/>
|
||||
|
||||
{/* 본문 */}
|
||||
<div className="flex">
|
||||
<div className={cn("flex flex-1", !isMain && "min-h-0")}>
|
||||
{/* 사이드바 - 고정 폰트 크기 */}
|
||||
{!isMain && (
|
||||
<Sidebar
|
||||
@@ -104,11 +115,17 @@ const MainLayout = ({ children, initialFontSize }: MainLayoutProps) => {
|
||||
|
||||
{/* 메인 콘텐츠만 가변 폰트 크기 적용 */}
|
||||
<main
|
||||
className="flex-1 p-4"
|
||||
className={cn(
|
||||
"flex-1 p-4",
|
||||
!isMain && "min-h-0 overflow-y-auto"
|
||||
)}
|
||||
// 전역 CSS 변수(--content-font-size)를 실제 렌더에 적용
|
||||
// SSR 단계에서의 초기 폰트 값을 FOUC 없이 유지하기 위해 fallback을 함께 지정
|
||||
style={{ fontSize: `var(--content-font-size, ${initialFontSize}px)` }}
|
||||
>
|
||||
{isViewProjectTitle &&
|
||||
<ProjectTitle/>
|
||||
}
|
||||
{children}
|
||||
</main>
|
||||
</div>
|
||||
|
||||
17
src/components/layout/ProjectTitle.tsx
Normal file
17
src/components/layout/ProjectTitle.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
|
||||
const ProjectTitle = () => {
|
||||
const mounted = useMounted();
|
||||
const { selectedProject } = useSelectedProject();
|
||||
|
||||
if(!mounted) return null;
|
||||
|
||||
return (
|
||||
<div className="flex justify-between items-center mb-2">
|
||||
<h1 className="font-bold content-text-2xl">{selectedProject?.prjctName}</h1>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProjectTitle
|
||||
@@ -1,9 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { ChevronDown } from "lucide-react";
|
||||
import { SideMenuItem } from "@/config/menu.types";
|
||||
import {KriSingleSelect} from "@/components/common/KriAutoComplete";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {SidebarProjectSearch} from "@/components/layout/SidebarProjectSearch ";
|
||||
|
||||
interface SidebarProps {
|
||||
isProjectMenu: boolean;
|
||||
@@ -51,15 +53,9 @@ export const Sidebar = ({
|
||||
`}
|
||||
>
|
||||
<div className="p-4 space-y-4 overflow-y-auto h-full">
|
||||
{isProjectMenu && (
|
||||
<div className="space-y-2">
|
||||
<Input
|
||||
type="text"
|
||||
placeholder="프로젝트 검색..."
|
||||
className="w-full"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{isProjectMenu &&
|
||||
<SidebarProjectSearch/>
|
||||
}
|
||||
|
||||
{/* 좌측 메뉴 */}
|
||||
<nav className="space-y-1">
|
||||
|
||||
63
src/components/layout/SidebarProjectSearch .tsx
Normal file
63
src/components/layout/SidebarProjectSearch .tsx
Normal file
@@ -0,0 +1,63 @@
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {ProjectInfo} from "@/types/project";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {useEffect, useState} from "react";
|
||||
import {KriSingleSelect} from "@/components/common/KriAutoComplete";
|
||||
import {useSelectedProject} from "@/hooks/useSelectedProject";
|
||||
import {useLoading} from "@/hooks/useLoading";
|
||||
import {useMounted} from "@/hooks/useMounted";
|
||||
import {PROJECT_SEARCH_COUNT} from "@/const/projectConst";
|
||||
import {SelectedProject} from "@/store/jotai/project";
|
||||
|
||||
export const SidebarProjectSearch = () =>{
|
||||
const mounted = useMounted();
|
||||
|
||||
const { selectedProject, setSelectedProject } = useSelectedProject();
|
||||
const [searchKeyword, setSearchKeyword] = useState(selectedProject?.prjctCd || "");
|
||||
const debouncedKeyword = useDebouncedValue(searchKeyword, 500);
|
||||
const [projectArray, setProjectArray] = useState<SelectedProject[]>([]);
|
||||
|
||||
const searchTopProject = async (keyword: string) => {
|
||||
const res = await nextApi.get<ProjectInfo[]>(
|
||||
`/project/top/${PROJECT_SEARCH_COUNT}`,
|
||||
{ query: { keyword } }
|
||||
);
|
||||
|
||||
setProjectArray(res);
|
||||
};
|
||||
|
||||
const handleSelectProject = (info:SelectedProject|null) => {
|
||||
if(info === null) return;
|
||||
|
||||
setSelectedProject(info);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if(selectedProject){
|
||||
const keyword = debouncedKeyword.trim();
|
||||
searchTopProject(keyword);
|
||||
}
|
||||
}, [debouncedKeyword]);
|
||||
|
||||
if (!mounted || !selectedProject) return null
|
||||
|
||||
return (
|
||||
<KriSingleSelect
|
||||
<SelectedProject>
|
||||
items={projectArray}
|
||||
value={String(selectedProject.prjctIdx)}
|
||||
onChange={() => {}}
|
||||
withInfo
|
||||
onItemChange={handleSelectProject}
|
||||
searchMode="inputOnly"
|
||||
onSearchValueChange={setSearchKeyword}
|
||||
placeholder="프로젝트 검색..."
|
||||
widthClassName="w-full"
|
||||
heightClassName="h-9"
|
||||
preventDeselect
|
||||
hideOptionCheck
|
||||
getLabel={(item) => `${item.prjctCd}_${item.prjctName}`}
|
||||
getValue={(item) => String(item.prjctIdx)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
66
src/components/ui/tabs.tsx
Normal file
66
src/components/ui/tabs.tsx
Normal file
@@ -0,0 +1,66 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import * as TabsPrimitive from "@radix-ui/react-tabs"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Tabs({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
|
||||
return (
|
||||
<TabsPrimitive.Root
|
||||
data-slot="tabs"
|
||||
className={cn("flex flex-col gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsList({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.List>) {
|
||||
return (
|
||||
<TabsPrimitive.List
|
||||
data-slot="tabs-list"
|
||||
className={cn(
|
||||
"bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsTrigger({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
|
||||
return (
|
||||
<TabsPrimitive.Trigger
|
||||
data-slot="tabs-trigger"
|
||||
className={cn(
|
||||
"data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function TabsContent({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof TabsPrimitive.Content>) {
|
||||
return (
|
||||
<TabsPrimitive.Content
|
||||
data-slot="tabs-content"
|
||||
className={cn("flex-1 outline-none", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Tabs, TabsList, TabsTrigger, TabsContent }
|
||||
Reference in New Issue
Block a user