Skip to content

Commit

Permalink
Fix : Profile input bug
Browse files Browse the repository at this point in the history
  • Loading branch information
oikkoikk committed Oct 4, 2023
1 parent 1fd3495 commit 96e0ec9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/components/gnb/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ export default function NavBar({ logo, profileDropdown }: Props) {

const profileButtonClickHandler = async () => {
if (isEditMode) {
console.log('updateUserProfile')
mutate();
await update({ ...session, name });
}
setIsEditMode(!isEditMode);
setIsEditMode((prev) => !prev);
};

const { mutate } = useMutation(() => updateUserProfile(name), {
Expand Down
14 changes: 6 additions & 8 deletions src/components/gnb/ProfileDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Props = {
isEditMode: boolean;
profileDropdown?: ProfileDropdown[];
setName: React.Dispatch<React.SetStateAction<string>>;
profileButtonClickHandler: () => void;
profileButtonClickHandler: () => Promise<void>;
};

export default function ProfileDropdown({
Expand All @@ -26,9 +26,9 @@ export default function ProfileDropdown({
const inputRef = useRef<HTMLInputElement>(null);

const enterKeyDownHandler = useCallback(
(e: KeyboardEvent) => {
if (e.key === 'Enter') {
profileButtonClickHandler();
async (e: string) => {
if (e === 'Enter') {
await profileButtonClickHandler();
}
},
[profileButtonClickHandler]
Expand All @@ -44,11 +44,8 @@ export default function ProfileDropdown({
inputRef.current.value.length
);
inputRef.current.value = name;
inputRef.current.addEventListener('keydown', enterKeyDownHandler);
} else {
inputRef.current.removeEventListener('keydown', enterKeyDownHandler);
}
}, [name, isEditMode, enterKeyDownHandler]);
}, [name, isEditMode]);

return (
<>
Expand All @@ -74,6 +71,7 @@ export default function ProfileDropdown({
disabled={isEditMode === false}
spellCheck='false'
onChange={(e) => setName(e.target.value.trim())}
onKeyDown={(e) => enterKeyDownHandler(e.key)}
maxLength={10}
className='hidden w-32 p-1 text-xs font-semibold leading-9 text-left resize-none sm:block md:text-sm lg:text-base disabled:bg-sroom-white'
/>
Expand Down

0 comments on commit 96e0ec9

Please sign in to comment.