Skip to content

Commit

Permalink
[Feature] Feedback 0710 (#32)
Browse files Browse the repository at this point in the history
* design: 용어목록 타이틀과 표 사이 간격 조절

* feat: 용어 모달 유효성 검사 개선
  • Loading branch information
hin6150 authored Jul 10, 2024
1 parent 112761d commit aa1aa48
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const textContainer = style({
display: 'flex',
alignItems: 'center',
gap: 5,
marginBottom: 20,
})

export const termTitleContainer = style({
Expand Down
60 changes: 31 additions & 29 deletions apps/web/src/modals/TermModal/TermModal.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use client'

import { Button, Text } from '@vook-client/design-system'
import { Button } from '@vook-client/design-system'
import { useForm } from 'react-hook-form'
import { useAddTermMutation, useEditTermMutation } from '@vook-client/api'
import { useQueryClient } from '@tanstack/react-query'
import { usePathname } from 'next/navigation'
import { useMemo } from 'react'

import { useModal } from '@/hooks/useModal'
import { useToast } from '@/hooks/useToast'
import { useVocabularyStore } from '@/store/term'

import { Modal } from '../Modal/Modal'
import { modalLowerTextGroup } from '../Modal/Modal.css'

export interface TermFormValues {
name: string
Expand All @@ -28,7 +28,8 @@ export const TermCreateModal = () => {
register,
handleSubmit,
watch,
formState: { errors },
formState,
// formState: { errors },
} = useForm<TermFormValues>()
const queryClient = useQueryClient()
const { addToast } = useToast()
Expand Down Expand Up @@ -59,6 +60,14 @@ export const TermCreateModal = () => {
},
)

const canSubmit = useMemo(
() =>
!formState.isValid ||
addTermMutation.isPending ||
addTermMutation.isSuccess,
[formState.isValid, addTermMutation.isPending, addTermMutation.isSuccess],
)

const onSubmit = handleSubmit(() => {
addTermMutation.mutate()
})
Expand All @@ -75,11 +84,11 @@ export const TermCreateModal = () => {
>
용어
</Modal.InputForm>
<div className={modalLowerTextGroup}>
{/* <div className={modalLowerTextGroup}>
<Text type="label" color="status-error">
{errors.name && '용어를 입력해 주세요.'}
</Text>
</div>
</div> */}

<Modal.Textarea
register={register}
Expand All @@ -89,7 +98,7 @@ export const TermCreateModal = () => {
동의어(선택)
</Modal.Textarea>
<Modal.LowerTextGroup
leftText=""
// leftText=""
RightText={watch('synonyms') ? watch('synonyms').length : 0}
/>

Expand All @@ -102,7 +111,7 @@ export const TermCreateModal = () => {
</Modal.Textarea>
<Modal.LowerTextGroup
leftText={errors.meaning && '뜻을 입력해 주세요.'}
// leftText={errors.meaning && '뜻을 입력해 주세요.'}
RightText={watch('meaning') ? watch('meaning').length : 0}
/>

Expand All @@ -116,12 +125,7 @@ export const TermCreateModal = () => {
>
취소
</Button>
<Button
size="middle"
fit="fill"
type="submit"
disabled={addTermMutation.isPending}
>
<Button size="middle" fit="fill" type="submit" disabled={canSubmit}>
생성
</Button>
</Modal.ButtonGroup>
Expand All @@ -137,12 +141,7 @@ export const TermEditModal = () => {
const { toggleModal } = useModal()
const { modalData } = useVocabularyStore()

const {
register,
handleSubmit,
watch,
formState: { errors },
} = useForm<TermFormValues>({
const { register, handleSubmit, watch, formState } = useForm<TermFormValues>({
defaultValues: {
name: modalData.name,
meaning: modalData.meaning,
Expand Down Expand Up @@ -178,6 +177,14 @@ export const TermEditModal = () => {
},
)

const canSubmit = useMemo(
() =>
!formState.isValid ||
editTermMutation.isPending ||
editTermMutation.isSuccess,
[formState.isValid, editTermMutation.isPending, editTermMutation.isSuccess],
)

const onSubmit = handleSubmit(() => {
editTermMutation.mutate()
})
Expand All @@ -194,11 +201,11 @@ export const TermEditModal = () => {
>
용어
</Modal.InputForm>
<div className={modalLowerTextGroup}>
{/* <div className={modalLowerTextGroup}>
<Text type="label" color="status-error">
{errors.name && '용어를 입력해 주세요.'}
</Text>
</div>
</div> */}

<Modal.Textarea
register={register}
Expand All @@ -208,7 +215,7 @@ export const TermEditModal = () => {
동의어(선택)
</Modal.Textarea>
<Modal.LowerTextGroup
leftText=""
// leftText=""
RightText={watch('synonyms') ? watch('synonyms').length : 0}
/>

Expand All @@ -221,7 +228,7 @@ export const TermEditModal = () => {
</Modal.Textarea>
<Modal.LowerTextGroup
leftText={errors.meaning && '뜻을 입력해 주세요.'}
// leftText={errors.meaning && '뜻을 입력해 주세요.'}
RightText={watch('meaning') ? watch('meaning').length : 0}
/>

Expand All @@ -235,12 +242,7 @@ export const TermEditModal = () => {
>
취소
</Button>
<Button
size="middle"
fit="fill"
type="submit"
disabled={editTermMutation.isPending}
>
<Button size="middle" fit="fill" type="submit" disabled={canSubmit}>
수정
</Button>
</Modal.ButtonGroup>
Expand Down

0 comments on commit aa1aa48

Please sign in to comment.