Skip to content

Commit

Permalink
fix: (#837) 마감시간 초기화 시 버튼 타입 미지정으로submit 되는 오류 수정
Browse files Browse the repository at this point in the history
- 모달에 넣는 buttonInfo가 ButtonHTMLAttributes 상속하게 만들어 type을 지정할 수 있도록 함
- 모달과 폼에서 모두 사용되어 타입을 전역 타입폴더로 분리
  • Loading branch information
chsua committed Nov 8, 2023
1 parent 3e49d0d commit 61830c5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
7 changes: 5 additions & 2 deletions frontend/src/components/PostForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Navigate, useNavigate } from 'react-router-dom';

import { ResponsiveFlex } from 'votogether-design-system';

import { ButtonInfo } from '@type/modalButton';
import { PostInfo } from '@type/post';

import { useMultiSelect, useContentImage, useText, useToggle, useWritingOption } from '@hooks';
Expand Down Expand Up @@ -154,14 +155,16 @@ export default function PostForm({ data, mutate, isSubmitting }: PostFormProps)
}
};

const primaryButton = {
const primaryButton: ButtonInfo = {
text: '저장',
handleClick: handleModalClose,
type: 'button',
};

const secondaryButton = {
const secondaryButton: ButtonInfo = {
text: '초기화',
handleClick: handleResetButton,
type: 'button',
};

return (
Expand Down
24 changes: 12 additions & 12 deletions frontend/src/components/common/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import React, { useEffect, useRef, PropsWithChildren } from 'react';
import { useEffect, useRef, PropsWithChildren } from 'react';

import { ButtonInfo } from '@type/modalButton';
import { Size } from '@type/style';

import SquareButton from '../SquareButton';

import * as S from './style';

interface ButtonProps {
text: string;
handleClick: () => void;
}

interface ModalProps extends PropsWithChildren {
title?: string;
size?: Size;
primaryButton: ButtonProps;
secondaryButton: ButtonProps;
primaryButton: ButtonInfo;
secondaryButton: ButtonInfo;
handleModalClose: () => void;
}

Expand All @@ -29,8 +25,12 @@ export default function Modal({
}: ModalProps) {
const BackDropRef = useRef<HTMLDivElement>(null);

const { text: primaryText, handleClick: primaryClick } = primaryButton;
const { text: secondaryText, handleClick: secondaryClick } = secondaryButton;
const { text: primaryText, handleClick: primaryClick, ...primaryButtonRest } = primaryButton;
const {
text: secondaryText,
handleClick: secondaryClick,
...secondaryButtonRest
} = secondaryButton;

useEffect(() => {
const handler = (e: MouseEvent) => {
Expand Down Expand Up @@ -59,12 +59,12 @@ export default function Modal({
{children && <S.Body>{children}</S.Body>}
<S.ButtonContainer>
<S.ButtonWrapper>
<SquareButton onClick={secondaryClick} theme="gray">
<SquareButton onClick={secondaryClick} theme="gray" {...secondaryButtonRest}>
{secondaryText}
</SquareButton>
</S.ButtonWrapper>
<S.ButtonWrapper>
<SquareButton onClick={primaryClick} theme="fill">
<SquareButton onClick={primaryClick} theme="fill" {...primaryButtonRest}>
{primaryText}
</SquareButton>
</S.ButtonWrapper>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/types/modalButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ButtonHTMLAttributes } from 'react';

export interface ButtonInfo extends ButtonHTMLAttributes<HTMLButtonElement> {
text: string;
handleClick: () => void;
}

0 comments on commit 61830c5

Please sign in to comment.