-
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.
Merge pull request #208 from FinalDoubleTen/FE-95--feat/Share
�Feat: 공유 기능 구현
- Loading branch information
Showing
19 changed files
with
541 additions
and
13 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -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,38 @@ | ||
import CopyToast from './CopyToast'; | ||
|
||
interface Props { | ||
title: string; | ||
subTitle: string; | ||
copyValue: string; | ||
} | ||
|
||
const CopyBox = ({ title, subTitle, copyValue }: Props) => { | ||
const onCopyClick = () => { | ||
navigator.clipboard.writeText(copyValue); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div className="mb-4 flex flex-col gap-1"> | ||
<span className="title3 text-gray7">{`${title} 복사`}</span> | ||
<span className="body6 text-gray4">{subTitle}</span> | ||
</div> | ||
<div className="flex h-12 w-full items-center justify-between rounded-lg border border-solid border-gray2 px-4 py-2"> | ||
<input | ||
className="body5 mr-4 w-full text-gray6 outline-none" | ||
readOnly | ||
value={copyValue} | ||
/> | ||
<CopyToast title={title}> | ||
<div | ||
onClick={onCopyClick} | ||
className="bg-main3 body3 w-12 rounded-lg p-2 text-main1"> | ||
복사 | ||
</div> | ||
</CopyToast> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CopyBox; |
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,36 @@ | ||
import * as Toast from '@radix-ui/react-toast'; | ||
import { ReactNode, useState } from 'react'; | ||
import { ReactComponent as CircleCheckIcon } from '@assets/images/CircleCheck.svg'; | ||
|
||
interface Props { | ||
title: string; | ||
children: ReactNode; | ||
} | ||
|
||
const CopyToast = ({ title, children }: Props) => { | ||
const [open, setOpen] = useState(false); | ||
|
||
return ( | ||
<Toast.Provider duration={2000}> | ||
<button | ||
onClick={() => { | ||
setOpen(true); | ||
}}> | ||
{children} | ||
</button> | ||
|
||
<Toast.Root | ||
className="bg-main4 flex h-16 w-[370px] items-center rounded-lg border border-solid border-main2 px-4 py-2 shadow-md" | ||
open={open} | ||
onOpenChange={setOpen}> | ||
<CircleCheckIcon fill="#29DDF6" className="mr-2" /> | ||
<Toast.Title className="body4 text-main1 [grid-area:_title]"> | ||
{`${title}가 복사되었습니다.`} | ||
</Toast.Title> | ||
</Toast.Root> | ||
<Toast.Viewport className="fixed left-[50%] top-12 translate-x-[-50%]" /> | ||
</Toast.Provider> | ||
); | ||
}; | ||
|
||
export default CopyToast; |
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,68 @@ | ||
import * as Dialog from '@radix-ui/react-dialog'; | ||
import { EditStarIcon } from '@components/common/icons/Icons'; | ||
import Alert from '@components/common/alert/Alert'; | ||
import { useLocation, useNavigate } from 'react-router-dom'; | ||
import { getItem } from '@utils/localStorageFun'; | ||
|
||
interface Props { | ||
isEditable: boolean; | ||
setIsEditable: React.Dispatch<React.SetStateAction<boolean>>; | ||
} | ||
|
||
const IsEditableModal = ({ isEditable, setIsEditable }: Props) => { | ||
const navigate = useNavigate(); | ||
const { pathname } = useLocation(); | ||
|
||
const isLogin = getItem('accessToken'); | ||
|
||
const handleConfirm = () => { | ||
navigate('/login', { state: { prevPath: `${pathname}/code` } }); | ||
}; | ||
|
||
return ( | ||
<Dialog.Root open={isEditable} onOpenChange={setIsEditable} modal> | ||
<Dialog.Portal> | ||
<Dialog.Overlay className="data-[state=open]:animate-overlayShow fixed inset-0 z-10 bg-black opacity-70" /> | ||
<Dialog.Content className="data-[state=open]:animate-contentShow fixed bottom-0 left-[50%] z-10 flex w-[412px] translate-x-[-50%] flex-col items-center rounded-t-2xl bg-white px-5 pb-8 pt-9"> | ||
<Dialog.Title className="title3 pb-2.5 text-center text-gray7"> | ||
편집 참여 코드를 입력하시면 | ||
<br /> | ||
여행 계획을 함께 편집할 수 있어요! | ||
</Dialog.Title> | ||
<Dialog.Description className="pb-8"> | ||
<EditStarIcon /> | ||
</Dialog.Description> | ||
{isLogin ? ( | ||
<button | ||
onClick={() => { | ||
navigate('code'); | ||
}} | ||
className="headline1 mb-4 h-14 w-full rounded-lg bg-main2 text-white outline-none"> | ||
초대코드 입력하기 | ||
</button> | ||
) : ( | ||
<Alert | ||
title={'로그인'} | ||
message={ | ||
<> | ||
편집 참여 코드 입력을 위해 로그인이 필요해요. | ||
<br /> | ||
로그인하시겠어요? | ||
</> | ||
} | ||
onConfirm={handleConfirm}> | ||
<button className="headline1 mb-4 h-14 w-full rounded-lg bg-main2 text-white outline-none"> | ||
초대코드 입력하기 | ||
</button> | ||
</Alert> | ||
)} | ||
<Dialog.Close> | ||
<button className="body1 text-gray5">보기만 할게요</button> | ||
</Dialog.Close> | ||
</Dialog.Content> | ||
</Dialog.Portal> | ||
</Dialog.Root> | ||
); | ||
}; | ||
|
||
export default IsEditableModal; |
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
Oops, something went wrong.