Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat/CK-147] 골룸 생성 페이지 고도화 및 유효성 검사를 구현한다 #114

Merged
merged 20 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9a5bad7
feat: 입력받은 날짜가 현재를 기준으로 유효한지 판별하는 함수 구현
jw-r Aug 8, 2023
135104a
Merge branch 'develop-client' of https://github.com/woowacourse-teams…
jw-r Aug 9, 2023
f9cf402
feat: onChange가 발생했을 때, onSubmit이 발생했을 때 유효성 검사를 수행하도록 Hook 확장
jw-r Aug 10, 2023
175df49
chore: handleSubmit 함수에 대한 주석 추가
jw-r Aug 10, 2023
ca66909
feat: 코끼리끼리 InputField 구현
jw-r Aug 10, 2023
dd05190
design: number 타입일 떄의 스타일 추가
jw-r Aug 10, 2023
6d27e76
design: form을 section 별로 분리 및 스타일 재조정
jw-r Aug 10, 2023
84cb937
feat: 객체 내부의 yyyy-mm-dd 형식의 문자열을 yyyymmdd 형태로 변환하는 함수 구현
jw-r Aug 11, 2023
3678e9b
refactor: 외부에서 handleInputChange 함수의 타입과 에러 객체의 타입에 접근할 수 있도록 변경
jw-r Aug 11, 2023
8c02fa9
refactor: 각 Input의 validation을 하나의 함수로 작성하도록 리펙토링
jw-r Aug 11, 2023
06a12b8
refactor: useFormInput 중복 로직 제거 리펙토링
jw-r Aug 11, 2023
fffff00
refactor: validation 객체의 메서드 내부에서 모든 유효성 검사 로직을 수행하도록 변경
jw-r Aug 13, 2023
36e7bfc
design: 에러 메시지가 잘리지 않도록 스타일 수정
jw-r Aug 13, 2023
a765fb1
feat: any 타입을 최소화하도록 타입 리펙토링
jw-r Aug 14, 2023
419ffde
refactor: validation utils 함수 분리 및 테스트 코드 작성
jw-r Aug 14, 2023
7759c78
feat: isValidMaxValue 함수 구현 및 테스트 코드 작성
jw-r Aug 14, 2023
d5728d4
feat: 인원수에 대한 Input 추가
jw-r Aug 14, 2023
5d864ce
refactor: validation의 매직넘버와 에러 메시지를 상수화
jw-r Aug 14, 2023
cfec4a6
feat: InputField에 textarea 태그를 조건 분기로 추가
jw-r Aug 14, 2023
7292a5a
refactor: 로드맵 Info 맵핑
jw-r Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions client/src/components/_common/InputField/InputField.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import styled from 'styled-components';

export const InputField = styled.div`
box-sizing: content-box;
`;

export const FieldHeader = styled.div<{ size?: 'small' | 'normal' }>`
margin-bottom: ${({ size }) => (size === 'small' ? '0.8rem' : '1.8rem')};
`;

export const Label = styled.label<{ size?: 'small' | 'normal' }>`
${({ theme, size }) =>
size === 'small' ? theme.fonts.nav_text : theme.fonts.nav_title};
& > span {
color: ${({ theme }) => theme.colors.red};
}
`;

export const Description = styled.p`
${({ theme }) => theme.fonts.nav_text};
color: ${({ theme }) => theme.colors.gray300};
`;

export const InputBox = styled.div<{
size?: 'small' | 'normal';
type?: 'text' | 'date' | 'textarea' | 'number';
}>`
& > input {
${({ theme, size }) => (size === 'small' ? theme.fonts.button1 : theme.fonts.h2)};
width: ${({ size, type }) =>
type === 'number' ? '7rem' : size === 'small' ? '' : '100%'};
padding: ${({ size, type }) =>
type === 'number' ? '0.4rem' : size === 'small' ? '0.1rem' : '0.4rem'};

text-align: ${({ size }) => (size === 'small' ? 'center' : '')};

border: ${({ theme, type }) =>
type === 'number' ? `0.1rem solid ${theme.colors.black}` : 'none'};
border-bottom: ${({ theme }) => `0.1rem solid ${theme.colors.black}`};
border-radius: ${({ type }) => (type === 'number' ? '4px' : '')};
}

& > textarea {
${({ theme, size }) => (size === 'small' ? theme.fonts.button1 : theme.fonts.h2)};
width: 100%;
height: 15rem;
padding: 1.5rem 1rem;

border: ${({ theme }) => `3px solid ${theme.colors.main_dark}`};
border-radius: 8px;
}
`;

export const ErrorMessage = styled.p<{ size?: 'small' | 'normal' }>`
${({ theme }) => theme.fonts.button1};
position: absolute;
color: ${({ theme }) => theme.colors.red};
`;
55 changes: 55 additions & 0 deletions client/src/components/_common/InputField/InputField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { HandleInputChangeType } from '@hooks/_common/useFormInput';
import * as S from './InputField.styles';

type InputFieldProps = {
name: string;
value: string;
onChange: HandleInputChangeType;
label?: string;
type?: 'text' | 'date' | 'textarea' | 'number';
size?: 'small' | 'normal';
isRequired?: boolean;
description?: string;
placeholder?: string;
errorMessage?: string;
style?: { [key: string]: string };
};

const InputField = ({ ...props }: InputFieldProps) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여러 props를 받아서 Input을 사용할 수 있게 한거 너무 좋은 것 같아요!! 우디 고민한 티가 많이나고 너무 수고많았어요ㅠㅠ 조금 더 다듬어서 서비스 내 모든 input에 적용해켜봅시당!!
지금 당장은 아니고 리팩토링할 때 했으면 하는 부분들 여기에 정리해놨습니다!
https://www.notion.so/d0b3ea6e9cf44703ab9c3a10bb6e1b96

return (
<S.InputField style={props.style}>
<S.FieldHeader size={props.size}>
<S.Label htmlFor={props.name} size={props.size}>
{props.label}
{props.isRequired && <span>*</span>}
</S.Label>
{props.description && <S.Description>{props.description}</S.Description>}
</S.FieldHeader>
<S.InputBox size={props.size} type={props.type}>
{props.type === 'textarea' ? (
<textarea
id={props.name}
name={props.name}
Comment on lines +30 to +32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id는 왜 지정해준건지 궁금해요!!

placeholder={props.placeholder}
value={props.value}
onChange={props.onChange}
/>
) : (
<input
id={props.name}
name={props.name}
placeholder={props.placeholder}
value={props.value}
type={props.type === 'number' ? 'text' : props.type || 'text'}
onChange={props.onChange}
/>
)}
{props.errorMessage && (
<S.ErrorMessage size={props.size}>{props.errorMessage}</S.ErrorMessage>
)}
</S.InputBox>
</S.InputField>
);
};

export default InputField;
Original file line number Diff line number Diff line change
@@ -1,88 +1,18 @@
import media from '@/styles/media';
import { styled } from 'styled-components';

export const Form = styled.form``;

export const RoadmapInfo = styled.div`
${({ theme }) => theme.fonts.description4}
`;

export const InputField = styled.label`
width: 80%;
height: 80%;
color: ${({ theme }) => theme.colors.gray300};
&::placeholder {
${({ theme }) => theme.fonts.description4};
color: ${({ theme }) => theme.colors.gray200};
}
`;

export const Input = styled.input`
${({ theme }) => theme.fonts.nav_title}
width: 70%;
padding: 1rem 0.5rem;
color: ${({ theme }) => theme.colors.gray300};
border-bottom: ${({ theme }) => `0.1rem solid ${theme.colors.black}`};
&::placeholder {
${({ theme }) => theme.fonts.description4};
color: ${({ theme }) => theme.colors.gray200};
}

${media.mobile`
width:100%;
`}
`;

export const NodeSectionWrapper = styled.div`
display: flex;
column-gap: 2rem;
`;

export const NodeList = styled.form<{ nodeCount: number }>`
display: grid;
grid-template-rows: ${({ nodeCount }) => `repeat(${nodeCount}, 1fr)`};
row-gap: 2.4rem;
export const Form = styled.form`
margin: 6rem 0;
`;

export const NodeWrapper = styled.div`
export const SubmitButtonWrapper = styled.div`
display: flex;
align-items: center;
`;

export const NodeInfo = styled.div`
width: 18rem;
height: 18rem;
margin-right: 2rem;
padding: 2rem;

background-color: ${({ theme }) => theme.colors.gray100};
border-radius: 8px;
`;

export const NodeConfigs = styled.div`
display: flex;

& > *:not(:last-child) {
margin-right: 2rem;
justify-content: end;
margin-top: 3rem;

& > button {
padding: 1.8rem 3rem;
color: ${({ theme }) => theme.colors.white};
background-color: ${({ theme }) => theme.colors.main_dark};
border-radius: 8px;
}
`;

export const DateInput = styled.input`
padding: 0.7rem 0;
text-align: center;
background-color: ${({ theme }) => theme.colors.gray100};
border-radius: 4px;
`;

export const Textarea = styled.textarea`
width: 70%;
height: 16rem;
padding: 1rem 0.5rem;

border: ${({ theme }) => `0.1rem solid ${theme.colors.black}`};
border-radius: 8px;

${media.mobile`
width:100%;
`}
`;
Loading
Loading