Skip to content

Commit

Permalink
feat: 문의 제목, 문의 내용 글자수 검사 #80
Browse files Browse the repository at this point in the history
  • Loading branch information
imdaxsz committed Sep 7, 2023
1 parent e663c64 commit 4b522a1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
20 changes: 16 additions & 4 deletions src/features/common/routes/HelpDesk/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ export default function Form({ goPrev, inquiryTypeName, setSuccess }: Props) {
"이메일 형식이 올바르지 않습니다.",
];

const titleErrorMessage = [
"",
"문의 제목을 입력해 주세요.",
"문의 제목을 50자 내로 입력해 주세요.",
];

const contentErrorMessage = [
"",
"문의 내용을 입력해 주세요.",
"문의 내용을 1000자 내로 입력해 주세요.",
];

const handlerPrevClick = () => {
goPrev();
resetForm();
Expand Down Expand Up @@ -64,8 +76,8 @@ export default function Form({ goPrev, inquiryTypeName, setSuccess }: Props) {
type="text"
placeholder="제목을 입력해 주세요.(최대 50자)"
onChange={handleTitleChange}
warn={titleError}
message="문의 제목을 입력해 주세요."
warn={Boolean(titleError)}
message={titleError ? titleErrorMessage[titleError] : ""}
required
/>
</FormItem>
Expand All @@ -75,8 +87,8 @@ export default function Form({ goPrev, inquiryTypeName, setSuccess }: Props) {
value={inquiryContent}
onChange={handleContentChange}
placeholder="내용을 입력해 주세요.(최대 1,000자)"
warn={contentError}
message="문의 내용을 입력해 주세요."
warn={Boolean(contentError)}
message={contentError ? contentErrorMessage[contentError] : ""}
required
/>
</FormItem>
Expand Down
28 changes: 21 additions & 7 deletions src/features/common/routes/HelpDesk/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default function useForm({ setSuccess }: Props) {
const [inquiryContent, setInquiryContent] = useState("");

const [emailError, setEmailError] = useState<number>(0);
const [titleError, setTitleError] = useState(false);
const [contentError, setContentError] = useState(false);
const [titleError, setTitleError] = useState<number>(0);
const [contentError, setContentError] = useState<number>(0);

const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setEmail(e.target.value);
Expand All @@ -30,8 +30,8 @@ export default function useForm({ setSuccess }: Props) {
setTitle("");
setInquiryContent("");
setEmailError(0);
setTitleError(false);
setContentError(false);
setTitleError(0);
setContentError(0);
};

const send = () => {
Expand All @@ -41,10 +41,24 @@ export default function useForm({ setSuccess }: Props) {
else if (!emailPattern.test(email)) return 2;
else return 0;
});
setTitleError(() => title === "");
setContentError(() => inquiryContent === "");
setTitleError(() => {
if (title === "") return 1;
else if (title.length > 50) return 2;
else return 0;
});
setContentError(() => {
if (inquiryContent === "") return 1;
else if (inquiryContent.length > 1000) return 2;
else return 0;
});

const ok =
emailPattern.test(email) && title !== "" && inquiryContent !== "";
emailPattern.test(email) &&
title !== "" &&
title.length <= 50 &&
inquiryContent !== "" &&
inquiryContent.length <= 1000;

if (ok) {
// TODO: API 요청
console.log("전송");
Expand Down

0 comments on commit 4b522a1

Please sign in to comment.