-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create setting page and add change name feature
- Loading branch information
Showing
3 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
function Main() { | ||
import { LoginContainer, InputWithLabelContainer,Input, ButtonContainingIcon, DisabledButtonContainingIcon } from "@components"; | ||
import ErrorConfigs from "@errors/config"; | ||
import { Navigate } from "react-router-dom"; | ||
import { useState,useEffect } from "react"; | ||
import useFetchWithRendering from "@hooks/useFetchWithRendering"; | ||
import useFetchUpdate from "@hooks/useFetchUpdate"; | ||
import { getUserName,changeUserName } from "@apis/auth"; | ||
|
||
|
||
function Setting() { | ||
const [name, setName] = useState(''); | ||
const [data, error] = useFetchWithRendering(getUserName); | ||
const [loading, update] = useFetchUpdate(changeUserName); | ||
|
||
useEffect(() => { | ||
if(data){ | ||
setName(data); | ||
} | ||
}, [data]); | ||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
setName(e.target.value); | ||
} | ||
|
||
const onSubmit = async (e: React.FormEvent<HTMLFormElement>) => { | ||
e.preventDefault(); | ||
if(!name) return; | ||
update(name); | ||
} | ||
|
||
if(error) { | ||
const errorConfig = ErrorConfigs[Error.name]; | ||
if(errorConfig) | ||
return <Navigate to="/error" state={{message: errorConfig.toast(Error)}} /> | ||
return <Navigate to="/error" state={{message: "알 수 없는 오류가 발생했습니다."}} /> | ||
} | ||
|
||
return ( | ||
<div> | ||
Setting | ||
</div> | ||
<LoginContainer onSubmit={onSubmit}> | ||
<InputWithLabelContainer> | ||
<label>닉네임</label> | ||
<Input value={name} onChange={onChange} disabled={loading||!data}/> | ||
</InputWithLabelContainer> | ||
{!loading&&<ButtonContainingIcon type="submit">저장</ButtonContainingIcon>} | ||
{loading&&<DisabledButtonContainingIcon disabled>저장중...</DisabledButtonContainingIcon>} | ||
</LoginContainer> | ||
); | ||
} | ||
|
||
export default Main; | ||
export default Setting; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters