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

[FE] 모바일 환경에서 멤버 추가 시 전에 입력한 이름의 끝자리가 입력되는 문제 #639

Merged
merged 1 commit into from
Sep 26, 2024
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
15 changes: 11 additions & 4 deletions client/src/hooks/useMembersStep.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect, useState} from 'react';
import {RefObject, useEffect, useRef, useState} from 'react';
import {useNavigate} from 'react-router-dom';

import {BillInfo} from '@pages/AddBillFunnel/AddBillFunnel';
Expand All @@ -22,6 +22,7 @@ interface Props {
const useMembersStep = ({billInfo, setBillInfo, currentMembers, setStep}: Props) => {
const [errorMessage, setErrorMessage] = useState('');
const [nameInput, setNameInput] = useState('');
const inputRef = useRef<HTMLInputElement>(null);

const {postMembersAsync, isPending: isPendingPostMembers} = useRequestPostMembers();

Expand Down Expand Up @@ -59,15 +60,16 @@ const useMembersStep = ({billInfo, setBillInfo, currentMembers, setStep}: Props)
};

const handleNameInputEnter = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.nativeEvent.isComposing) {
return;
}
if (event.key === 'Enter' && canAddMembers) {
event.preventDefault();
if (!billInfo.members.map(({name}) => name).includes(nameInput)) {
setBillInfoMemberWithId(nameInput);
}
setNameInput('');
if (inputRef.current) {
inputRef.current.blur();
setTimeout(() => inputRef.current?.focus(), 0);
}
}
};

Expand Down Expand Up @@ -102,13 +104,18 @@ const useMembersStep = ({billInfo, setBillInfo, currentMembers, setStep}: Props)
}
}, [isSuccessPostBill]);

useEffect(() => {
console.log(nameInput);
}, [nameInput]);

const handlePrevStep = () => {
setStep('title');
};

return {
errorMessage,
nameInput,
inputRef,
handleNameInputChange,
handleNameInputEnter,
isPendingPostBill,
Expand Down
2 changes: 2 additions & 0 deletions client/src/pages/AddBillFunnel/steps/MembersStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const MembersStep = ({billInfo, setBillInfo, currentMembers, setStep}: Props) =>
const {
errorMessage,
nameInput,
inputRef,
handleNameInputChange,
handleNameInputEnter,
isPendingPostBill,
Expand All @@ -46,6 +47,7 @@ const MembersStep = ({billInfo, setBillInfo, currentMembers, setStep}: Props) =>
<Top.Line text="참여한 사람은 누구인가요?" emphasize={['참여한 사람']} />
</Top>
<LabelInput
ref={inputRef}
labelText="이름"
errorText={errorMessage ?? ''}
value={nameInput}
Expand Down
Loading