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

🚸 improve: ν”„λ‘œν•„ νŽΈμ§‘ νŽ˜μ΄μ§€ μŠ€νƒ€μΌλ§ 및 κΈ°λŠ₯ κ°œμ„  #94

Merged
merged 4 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
63 changes: 63 additions & 0 deletions src/components/domain/ValidationNoticeBar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { Text } from "@components/base";
import styled from "@emotion/styled";
import { css } from "@emotion/react";

interface Props {
errors: any;
value?: string;
limit?: number;
hasCount?: boolean;
}

const ValidationNoticeBar = ({
value,
limit,
hasCount = false,
errors,
}: Props) => {
return (
<Container>
{hasCount ? (
<LetterCount
size="sm"
strong
className={value!.length > limit! ? "error" : ""}
>
{value!.length}/{limit}
</LetterCount>
) : null}
<ErrorMessage size="sm">
{hasCount
? errors ??
(value!.length > limit! ? "μ œν•œ κΈ€μž 수λ₯Ό λ„˜μ—ˆμŠ΅λ‹ˆλ‹€." : "")
: errors}
</ErrorMessage>
</Container>
);
};

export default ValidationNoticeBar;

const Container = styled.div`
${({ theme }) => css`
display: flex;
padding: ${theme.gaps.xxs};
color: ${theme.colors.gray900};
`}
`;

const LetterCount = styled(Text)`
${({ theme }) => css`
&.error {
color: ${theme.colors.red.strong};
}
`}
`;

const ErrorMessage = styled(Text)`
${({ theme }) => css`
text-align: right;
flex-grow: 1;
color: ${theme.colors.red.strong};
`}
`;
7 changes: 7 additions & 0 deletions src/components/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ export { default as LoudSpeaker } from "./ReservationItem/Loudspeaker";
export { default as ReservationItem } from "./ReservationItem";
export { default as NewCourtItem } from "./NewCourtItem";
export type { NewCourt } from "./NewCourtItem/types";
export { PositionsPicker, ProficiencyPicker } from "./UserInfoPicker";
export type {
PositionKeyUnion,
ProficiencyKeyUnion,
} from "./UserInfoPicker/types";
export { default as ValidationNoticeBar } from "./ValidationNoticeBar";

// eslint-disable-next-line import/no-cycle
export { default as NotificationList } from "./NotificationList";
2 changes: 1 addition & 1 deletion src/contexts/NavigationProvider/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const reducer: Reducer<DataProps, ReducerAction> = (
return {
...prevState,
isTopNavigation: true,
isBottomNavigation: true,
isBottomNavigation: false,
currentPage: type,
isBack: true,
isNotifications: false,
Expand Down
106 changes: 72 additions & 34 deletions src/pages/user/edit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { useState, useCallback, ChangeEvent } from "react";
import { useState, useCallback, ChangeEvent, MouseEvent } from "react";
import { NextPage } from "next";
import Head from "next/head";
import styled from "@emotion/styled";

import UtilRoute from "UtilRoute";
import useForm, { Error } from "@hooks/useForm";
import { Avatar, Spacer, Upload } from "@components/base";
import Input from "@components/base/Input";
import { useNavigationContext } from "@contexts/hooks";
import { Avatar, Spacer, Upload, Button, Label, Input } from "@components/base";
import {
PositionKeyUnion,
ProficiencyKeyUnion,
} from "@components/domain/UserInfoPicker/types";
import {
BottomFixedButton,
PositionsPicker,
ProficiencyPicker,
} from "@components/domain/UserInfoPicker";
ValidationNoticeBar,
PositionKeyUnion,
ProficiencyKeyUnion,
} from "@components/domain";

interface Values {
nickname: string;
Expand All @@ -23,7 +24,7 @@ interface Values {
positions: PositionKeyUnion[];
}

const UserEditPage: NextPage = () => {
const UserEditPage: NextPage = UtilRoute("private", () => {
const { useMountPage } = useNavigationContext();
useMountPage((page) => page.USER_EDIT);

Expand All @@ -46,6 +47,11 @@ const UserEditPage: NextPage = () => {
const [selectedPositions, setSelectedPositions] =
useState<PositionKeyUnion[]>(positions);

const lengthLimit = {
nickname: 15,
description: 25,
};

const handleChangeProficiency = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
setSelectedProficiency(e.target.value as ProficiencyKeyUnion);
Expand All @@ -67,6 +73,10 @@ const UserEditPage: NextPage = () => {
[selectedPositions]
);

const handleDeleteProfileImage = (e: MouseEvent<HTMLButtonElement>) => {
alert("ν”„λ‘œν•„ 이미지 μ‚­μ œ API");
};

const { values, errors, isLoading, handleChange, handleSubmit } =
useForm<Values>({
initialValues: {
Expand All @@ -84,11 +94,17 @@ const UserEditPage: NextPage = () => {
};
alert(JSON.stringify(valueWithPosition));
},
validate: ({ nickname }) => {
validate: ({ nickname, description }) => {
const errors: Error<Values> = {};

if (!nickname) {
errors.nickname = "λ‹‰λ„€μž„μ„ ν•œ κΈ€μž 이상 μž…λ ₯ν•΄μ£Όμ„Έμš”.";
errors.nickname = "λ‹‰λ„€μž„μ€ λΉ„μ›Œλ‘˜ 수 μ—†μŠ΅λ‹ˆλ‹€.";
}
if (nickname.length > lengthLimit.nickname) {
errors.nickname = "15자 μ΄λ‚΄λ‘œ μž…λ ₯ν•΄μ£Όμ„Έμš”.";
}
if (description.length > lengthLimit.description) {
errors.description = "25자 μ΄λ‚΄λ‘œ μž…λ ₯ν•΄μ£Όμ„Έμš”.";
}
if (!selectedProficiency) {
errors.proficiency = "μˆ™λ ¨λ„λ₯Ό μ„ νƒν•΄μ£Όμ„Έμš”.";
Expand All @@ -108,19 +124,23 @@ const UserEditPage: NextPage = () => {
<meta name="description" content="ν˜Όμžμ„œλ„ 농ꡬλ₯Ό 더 λΉ λ₯΄κ²Œ" />
</Head>

<Center>
<Upload>
<Avatar
isEdit
src={profileImage ?? baseProfileImageUrl}
shape="circle"
__TYPE="Avatar"
/>
</Upload>
<button>κΈ°λ³Έ ν”„λ‘œν•„ μ΄λ―Έμ§€λ‘œ λ³€κ²½ν•˜κΈ°</button>
</Center>
<form onSubmit={handleSubmit}>
<Spacer gap="md" type="vertical">
<Center>
<Spacer gap="xs" type="vertical">
<Upload style={{ textAlign: "center" }}>
<Avatar
isEdit
src={profileImage ?? baseProfileImageUrl}
shape="circle"
__TYPE="Avatar"
/>
</Upload>
<Button onClick={handleDeleteProfileImage} type="button" secondary>
κΈ°λ³Έ ν”„λ‘œν•„ μ΄λ―Έμ§€λ‘œ λ³€κ²½ν•˜κΈ°
</Button>
</Spacer>
</Center>
<Container gap="md" type="vertical">
<div>
<Input
label="λ‹‰λ„€μž„"
Expand All @@ -130,9 +150,13 @@ const UserEditPage: NextPage = () => {
value={values.nickname}
isRequired
placeholder="15자 μ΄λ‚΄μ˜ λ‹‰λ„€μž„μ„ μž…λ ₯ν•΄μ£Όμ„Έμš”"
block
/>
<p>{errors.nickname}</p>
<ValidationNoticeBar
hasCount
value={values.nickname}
limit={lengthLimit.nickname}
errors={errors.nickname}
/>
</div>
<div>
<Input
Expand All @@ -142,32 +166,42 @@ const UserEditPage: NextPage = () => {
onChange={handleChange}
value={values.description}
placeholder="ex) μ €λŠ” 주둜 νŒŒμ›Œν¬μ›Œλ“œλ‘œ λ›°κ³ , λ‹Ήμ‚° μ£Όλ³€μ—μ„œ κ²Œμž„ν•΄μš”. μ–Έμ œλ“  μ—°λ½μ£Όμ„Έμš”."
block
/>
<p>{errors.description}</p>
<ValidationNoticeBar
hasCount
value={values.description}
limit={lengthLimit.description}
errors={errors.description}
/>
</div>
<div>
<p>μˆ™λ ¨λ„</p>
<Label isRequired>μˆ™λ ¨λ„</Label>
<ProficiencyPicker
selectedValue={selectedProficiency}
onChange={handleChangeProficiency}
/>
<span>{errors.proficiency}</span>
<ValidationNoticeBar
errors={errors.proficiency}
></ValidationNoticeBar>
</div>
<div>
<p>ν¬μ§€μ…˜</p>
<Label isRequired>ν¬μ§€μ…˜</Label>
<PositionsPicker
selectedValue={selectedPositions}
onChange={handleChangePositions}
/>
<span>{errors.positions}</span>
<ValidationNoticeBar
errors={errors.positions}
></ValidationNoticeBar>
</div>
</Spacer>
<button>ν”„λ‘œν•„ νŽΈμ§‘ μ™„λ£Œν•˜κΈ°</button>
</Container>
<BottomFixedButton type="submit" onClick={() => {}}>
ν”„λ‘œν•„ νŽΈμ§‘ μ™„λ£Œν•˜κΈ°
</BottomFixedButton>
</form>
</div>
);
};
});

export default UserEditPage;

Expand All @@ -177,3 +211,7 @@ const Center = styled.div`
justify-content: center;
align-items: center;
`;

const Container = styled(Spacer)`
padding: ${({ theme }) => `30px ${theme.gaps.base} 120px`};
`;