260722_01_ENH: 버그 수정 및 개선 사항 수정

This commit is contained in:
2026-07-22 16:53:00 +09:00
parent d8b565276d
commit 2dd5b88c6f
67 changed files with 1925 additions and 736 deletions

View File

@@ -1,6 +1,6 @@
'use client'
import { useEffect, useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { KriDialog } from '@/components/common/KriDialog'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
@@ -9,7 +9,9 @@ import { useDialog } from '@/hooks/useDialog'
import type { DialogId } from '@/store/jotai/dialog'
import type { CmpnInfoSaveRequest } from '@/types/cmpn'
import type { DataVerification } from "@kri/common";
import { apiError, NONE_HTTP_ERROR, UNKNOWN_HTTP_ERROR } from "@kri/common/http";
import { COMMON_TEXT_REGEX } from "@/const/validationConst";
import { validateValue } from "@/utils/validation";
import { formatKoreanPhoneNumber } from "@/utils/phone";
export type CmpnUpsertDialogProps = {
dialogId?: DialogId
@@ -43,6 +45,12 @@ const CmpnUpsertDialog = ({
const [formData, setFormData] = useState<CmpnInfoSaveRequest>(createDefaultCmpnInfo);
const [isCheckedDuplicate, setIsCheckedDuplicate] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const [invalidField, setInvalidField] = useState<'cmpnId' | 'cmpnAlias' | 'cmpnTel' | 'memo' | null>(null);
const cmpnIdRef = useRef<HTMLInputElement>(null);
const cmpnAliasRef = useRef<HTMLInputElement>(null);
const cmpnTelRef = useRef<HTMLInputElement>(null);
const memoRef = useRef<HTMLTextAreaElement>(null);
const resolvedOpen = open ?? isDialogOpen(dialogId);
@@ -57,6 +65,7 @@ const CmpnUpsertDialog = ({
}
useEffect(() => {
setInvalidField(null);
if (initialData) {
setFormData({
...createDefaultCmpnInfo(),
@@ -87,6 +96,8 @@ const CmpnUpsertDialog = ({
const cmpnId = formData.cmpnId.trim();
if (!cmpnId) {
alert("회사 ID를 입력해주세요.");
setInvalidField('cmpnId');
cmpnIdRef.current?.focus();
return;
}
@@ -105,18 +116,53 @@ const CmpnUpsertDialog = ({
}
const handleSubmit = async () => {
setInvalidField(null);
if (!formData.cmpnId.trim()) {
alert("회사 ID를 입력해주세요.");
setInvalidField('cmpnId');
cmpnIdRef.current?.focus();
return;
}
if (mode === 'create' && !isCheckedDuplicate) {
alert("회사 ID 중복체크를 해주세요.");
setInvalidField('cmpnId');
cmpnIdRef.current?.focus();
return;
}
if (!formData.cmpnAlias.trim()) {
alert("별칭을 입력해주세요.");
const cmpnAliasCheck = validateValue(formData.cmpnAlias, {
required: true,
requiredMessage: "별칭을 입력해주세요.",
maxLength: 32,
pattern: COMMON_TEXT_REGEX,
patternMessage: "별칭에 허용되지 않는 문자가 포함되어 있습니다.",
});
if (!cmpnAliasCheck.valid) {
alert(cmpnAliasCheck.message);
setInvalidField('cmpnAlias');
cmpnAliasRef.current?.focus();
return;
}
const cmpnTelCheck = validateValue(formData.cmpnTel ?? '', {
maxLength: 16,
pattern: COMMON_TEXT_REGEX,
patternMessage: "전화번호에 허용되지 않는 문자가 포함되어 있습니다.",
});
if (!cmpnTelCheck.valid) {
alert(cmpnTelCheck.message);
setInvalidField('cmpnTel');
cmpnTelRef.current?.focus();
return;
}
const memoCheck = validateValue(formData.memo ?? '', { maxLength: 2048 });
if (!memoCheck.valid) {
alert(memoCheck.message);
setInvalidField('memo');
memoRef.current?.focus();
return;
}
@@ -133,15 +179,7 @@ const CmpnUpsertDialog = ({
});
handleOpenChange(false);
} catch (e) {
const err = apiError(e, {
fallbackMessage: "Save failed.",
});
console.error(err.status, err.code, err.message);
if (err.code !== NONE_HTTP_ERROR && err.code !== UNKNOWN_HTTP_ERROR) {
alert(err.message);
} else {
alert("저장에 실패했습니다.");
}
console.error(e);
} finally {
setIsSubmitting(false);
}
@@ -180,11 +218,13 @@ const CmpnUpsertDialog = ({
</Label>
<div className="flex gap-2">
<Input
ref={cmpnIdRef}
id="cmpnId"
placeholder="Enter company ID"
placeholder="회사 ID를 입력하세요"
value={formData.cmpnId}
onChange={(e) => handleInputChange('cmpnId', e.target.value)}
disabled={mode === 'edit'}
aria-invalid={invalidField === 'cmpnId'}
/>
{mode === 'create' && (
<Button
@@ -200,30 +240,36 @@ const CmpnUpsertDialog = ({
<div className="grid gap-2">
<Label htmlFor="cmpnAlias">별칭</Label>
<Input
ref={cmpnAliasRef}
id="cmpnAlias"
placeholder="Enter alias"
placeholder="별칭을 입력하세요"
value={formData.cmpnAlias ?? ''}
onChange={(e) => handleInputChange('cmpnAlias', e.target.value)}
aria-invalid={invalidField === 'cmpnAlias'}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="cmpnTel">전화번호</Label>
<Input
ref={cmpnTelRef}
id="cmpnTel"
placeholder="Enter tel"
value={formData.cmpnTel ?? ''}
onChange={(e) => handleInputChange('cmpnTel', e.target.value)}
placeholder="전화번호를 입력하세요"
value={formatKoreanPhoneNumber(formData.cmpnTel ?? '')}
onChange={(e) => handleInputChange('cmpnTel', e.target.value.replace(/\D/g, ''))}
aria-invalid={invalidField === 'cmpnTel'}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="memo">메모</Label>
<textarea
ref={memoRef}
id="memo"
className="flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
className="flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20"
rows={3}
placeholder="Enter memo"
placeholder="메모를 입력하세요"
value={formData.memo ?? ''}
onChange={(e) => handleInputChange('memo', e.target.value)}
aria-invalid={invalidField === 'memo'}
/>
</div>
</KriDialog>