-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
109 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
interface Props { | ||
inputCode: string; | ||
setInputCode: React.Dispatch<React.SetStateAction<string>>; | ||
showError: boolean; | ||
} | ||
|
||
const CodeInput = ({ inputCode, setInputCode, showError }: Props) => { | ||
const onCodeChange = async (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const changeValue = e.target.value; | ||
if (changeValue.length <= 5) { | ||
setInputCode(e.target.value); | ||
} | ||
}; | ||
return ( | ||
<div className="relative flex w-full flex-col items-start px-2 "> | ||
<div | ||
className={`mb-10 mt-6 w-full border-b-[1.5px] border-solid ${ | ||
showError ? 'border-red' : 'border-gray3 focus-within:border-main2' | ||
}`}> | ||
<input | ||
type="number" | ||
autoFocus | ||
maxLength={5} | ||
placeholder="편집 초대 코드를 입력해주세요." | ||
className="title3 mb-2 h-5 w-full bg-transparent text-gray4 outline-none placeholder:text-gray2" | ||
onChange={onCodeChange} | ||
value={inputCode} | ||
/> | ||
</div> | ||
{showError && ( | ||
<div className="body5 absolute top-[62px] text-red"> | ||
편집 참여 코드를 다시 한번 확인해주세요. | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CodeInput; |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { postTripsjoin } from '@api/trips'; | ||
import CodeInput from '@components/Share/CodeInput'; | ||
import Alert from '@components/common/alert/Alert'; | ||
import { useGetTripsAuthority } from '@hooks/useGetTripsAuthority'; | ||
import { useState } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
const EditCodeModal = () => { | ||
const [isModalOpen, setIsModalOpen] = useState<boolean>(false); | ||
const [inputCode, setInputCode] = useState<string>(''); | ||
const [showError, setShowError] = useState<boolean>(false); | ||
|
||
const { id: tripId } = useParams(); | ||
const { tripAuthority } = useGetTripsAuthority(); | ||
|
||
const handleConfirm = async () => { | ||
if (tripId) { | ||
try { | ||
const { data } = await postTripsjoin(Number(tripId), inputCode); | ||
if (data.status === 200) { | ||
setIsModalOpen(false); | ||
} | ||
} catch (err) { | ||
setShowError(true); | ||
setInputCode(''); | ||
console.error('참여 코드 요청 중 에러 발생', err); | ||
} | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{tripAuthority === 'WRITE' ? ( | ||
<button className="body3 rounded-lg border-2 border-solid border-gray2 p-2 text-gray4"> | ||
편집 | ||
</button> | ||
) : ( | ||
<Alert | ||
title="편집 참여 코드 입력" | ||
content={ | ||
<CodeInput | ||
inputCode={inputCode} | ||
setInputCode={setInputCode} | ||
showError={showError} | ||
/> | ||
} | ||
isOpen={isModalOpen} | ||
setIsOpen={setIsModalOpen} | ||
onConfirm={handleConfirm}> | ||
<button className="body3 rounded-lg border-2 border-solid border-gray2 p-2 text-gray4"> | ||
편집 | ||
</button> | ||
</Alert> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default EditCodeModal; |
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