Skip to content

Commit

Permalink
fix: 최초 사용자 404 에러 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
corinthionia committed Aug 5, 2023
1 parent 5670fda commit 2b24b63
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/components/addTimeTable/AddTimeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ const AddTimeTable = ({
document.body.style.overflow = '';
(wrapperRef.current as HTMLDivElement).style.overflow = 'auto';

navigate(`/${ROUTES.CURRENT}/${roomUUID}`);
navigate(`${ROUTES.CURRENT}/${roomUUID}`);
};

const allTimeRange = getAllTimeRange(dates, timeRange);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useFormInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { PostAuthType } from '../types/auth';

const useInputs = (initialForm: PostAuthType) => {
const [form, setForm] = useState(initialForm);
const onChange = useCallback(
const onChangeForm = useCallback(
(e: any) => {
const { name, value } = e.target;
setForm({ ...form, [name]: value });
},
[form]
);
const reset = useCallback(() => setForm(initialForm), [initialForm]);
return { form, onChange, reset };
return { form, onChangeForm, reset };
};

export default useInputs;
38 changes: 19 additions & 19 deletions src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Login = () => {
useInputScroll(inputNameRef);
useInputScroll(inputPasswordRef);

const { form, onChange } = useInputs({
const { form, onChangeForm } = useInputs({
name: '',
password: '',
});
Expand All @@ -56,35 +56,40 @@ const Login = () => {
const navigate = useNavigate();

const { data } = useGetRoomInfo(roomUUID);
const { mutate } = usePostUserInfo();
const { mutate, isSuccess, isError } = usePostUserInfo();

useEffect(() => {
if (data) {
setRoom(data);
}
}, [data]);

const onClickNext = async () => {
try {
if (Number.isNaN(Number(form.password))) {
alert('비밀번호는 숫자만 입력해주세요');
return;
}
const onClickNext = () => {
if (Number.isNaN(Number(form.password))) {
alert('비밀번호는 숫자만 입력해주세요');
return;
}

if (canGoNext) {
mutate({ roomUUID, form });
}
};

useEffect(() => {
if (isSuccess) {
if (saveUserInfo) {
localStorage.setItem('name', form.name);
localStorage.setItem('uuid', String(roomUUID));
}

localStorage.setItem('userName', form.name);
navigate(`${ROUTES.ADD_TIME}/${roomUUID}`);
} catch {
}

if (isError) {
setIsPasswordError(true);
null;
}
};
}, [isSuccess, isError]);

return (
<MainContainer>
Expand All @@ -101,7 +106,7 @@ const Login = () => {
placeholder="이름을 입력하세요"
maxLength={4}
value={form.name}
onChange={onChange}
onChange={onChangeForm}
isPasswordError={isPasswordError}
></NameInput>
<PasswordInput
Expand All @@ -113,7 +118,7 @@ const Login = () => {
autoComplete="current-password"
placeholder="비밀번호 4자리를 설정하세요"
value={form.password}
onChange={onChange}
onChange={onChangeForm}
maxLength={4}
isPasswordError={isPasswordError}
></PasswordInput>
Expand All @@ -132,12 +137,7 @@ const Login = () => {
<TextWrapper>정보 저장</TextWrapper>
</RightWrapper>
</CheckBoxContainer>
{/* <Link to="/roomCalendar"> */}
<BottomButtonContainer
onClick={() => {
canGoNext ? onClickNext() : null;
}}
>
<BottomButtonContainer onClick={onClickNext}>
<BottomButton text={'로그인'} isActivated={canGoNext} />
</BottomButtonContainer>
</FormContainer>
Expand Down
2 changes: 1 addition & 1 deletion src/queries/availableTimes/useGetAvailableTimesByOne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const useGetAvailableTimesByOne = (
userName: string
) => {
return useQuery(
[QUERY_KEYS.AVAILABLE_TIME.GET_AVAILABLE_TIMES_BY_ONE, roomUUID],
[QUERY_KEYS.AVAILABLE_TIME.GET_AVAILABLE_TIMES_BY_ONE, roomUUID, userName],
() => getAvailableTimesByOne(roomUUID, userName)
);
};

0 comments on commit 2b24b63

Please sign in to comment.