-
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.
Merge pull request #78 from DDD-Community/feature/73
[Feature/73] 탈퇴 페이지 구현
- Loading branch information
Showing
17 changed files
with
298 additions
and
8 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,22 @@ | ||
import Modal from '@/components/Modal' | ||
import TwoPolaroidsIcon from 'public/icons/twopolaroids.svg' | ||
|
||
interface LeaveConfirmModalProps { | ||
isOpen: boolean | ||
onClose: () => void | ||
} | ||
const LeaveConfirmModal = ({ isOpen, onClose }: LeaveConfirmModalProps) => { | ||
const title = 'POLABO 탈퇴가 완료되었습니다.' | ||
const content = '그동안 POLABO를\n이용해주셔서 감사합니다.' | ||
return ( | ||
<Modal isOpen={isOpen} onClose={onClose} closeOnOutsideClick={false}> | ||
<Modal.CenterModal icon={<TwoPolaroidsIcon />}> | ||
<Modal.Title>{title}</Modal.Title> | ||
<Modal.Content>{content}</Modal.Content> | ||
<Modal.CenterConfirm confirmText="확인" /> | ||
</Modal.CenterModal> | ||
</Modal> | ||
) | ||
} | ||
|
||
export default LeaveConfirmModal |
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,91 @@ | ||
'use client' | ||
|
||
import TextArea from '@/components/TextArea' | ||
import Button from '@/components/Button' | ||
import { useEffect, useState } from 'react' | ||
import Select from '@/components/Select' | ||
import { withdraw } from '@/lib' | ||
import { signOut } from 'next-auth/react' | ||
import LeaveConfirmModal from './LeaveConfirmModal' | ||
|
||
const WITHDRAW_TYPE = { | ||
SELECT: '선택해주세요.', | ||
UNUSED: '더 이상 이용하지 않아요.', | ||
PRIVACY: '개인정보가 걱정돼요.', | ||
DELETE_DATA: '제 데이터를 삭제하고 싶어요.', | ||
NEW_ACCOUNT: '새로운 계정을 만들고 싶어요.', | ||
ETC: '기타', | ||
} | ||
|
||
const LeaveForm = () => { | ||
const [withdrawType, setWithdrawType] = useState<string>(WITHDRAW_TYPE.SELECT) | ||
const [customReason, setCustomReason] = useState<string>('') | ||
const [isFormValid, setIsFormValid] = useState<boolean>(false) | ||
const [isLeaveConfirmModalOpen, setIsLeaveConfirmModalOpen] = useState(false) | ||
const errorMessage = | ||
customReason.length > 50 ? '50자까지 입력 가능합니다.' : '' | ||
const isCustomReasonValid = customReason && !errorMessage | ||
|
||
useEffect(() => { | ||
if (withdrawType === WITHDRAW_TYPE.SELECT) { | ||
setIsFormValid(false) | ||
} else if (withdrawType === WITHDRAW_TYPE.ETC && !isCustomReasonValid) { | ||
setIsFormValid(false) | ||
} else { | ||
setIsFormValid(true) | ||
} | ||
}, [withdrawType, customReason]) | ||
|
||
const submit = async () => { | ||
if (!isFormValid) { | ||
return | ||
} | ||
|
||
await withdraw({ | ||
type: withdrawType, | ||
reason: customReason, | ||
}) | ||
|
||
setIsLeaveConfirmModalOpen(true) | ||
} | ||
|
||
const onCloseLeaveConfirmModal = () => { | ||
signOut({ callbackUrl: '/' }) | ||
} | ||
|
||
return ( | ||
<form className="flex flex-1 flex-col justify-between"> | ||
<div className="flex flex-col gap-8"> | ||
<Select | ||
value={withdrawType} | ||
options={Object.values(WITHDRAW_TYPE)} | ||
onSelect={setWithdrawType} | ||
/> | ||
{withdrawType === WITHDRAW_TYPE.ETC && ( | ||
<TextArea | ||
placeholder="이유를 입력해주세요." | ||
value={customReason} | ||
setValue={setCustomReason} | ||
description={`${customReason.length}/50`} | ||
hasError={!!errorMessage} | ||
errorMessage={errorMessage} | ||
/> | ||
)} | ||
</div> | ||
<Button | ||
size="lg" | ||
onClick={submit} | ||
disabled={!isFormValid} | ||
className="w-full" | ||
> | ||
탈퇴하기 | ||
</Button> | ||
<LeaveConfirmModal | ||
isOpen={isLeaveConfirmModalOpen} | ||
onClose={onCloseLeaveConfirmModal} | ||
/> | ||
</form> | ||
) | ||
} | ||
|
||
export default LeaveForm |
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,7 @@ | ||
import { ReactNode } from 'react' | ||
|
||
const Title = ({ children }: { children: ReactNode }) => { | ||
return <h1 className="mb-3.5 text-xl font-semiBold">{children}</h1> | ||
} | ||
|
||
export default Title |
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,67 @@ | ||
'use client' | ||
|
||
import ArrowUpIcon from 'public/icons/arrow_up.svg' | ||
import ArrowDownIcon from 'public/icons/arrow_down.svg' | ||
import CheckIcon from 'public/icons/check.svg' | ||
import { useState } from 'react' | ||
|
||
interface SelectOptionProps { | ||
text: string | ||
selected: boolean | ||
onSelect: (value: string) => void | ||
} | ||
|
||
const SelectOption = ({ text, selected, onSelect }: SelectOptionProps) => { | ||
return ( | ||
<button | ||
type="button" | ||
onClick={() => onSelect(text)} | ||
className="ml-1.5 grid grid-cols-[13px_minmax(0,1fr)] items-center justify-items-start gap-1 border-b-[0.5px] border-b-gray-200 py-1.5 text-sm active:bg-gray-100" | ||
> | ||
{selected ? <CheckIcon /> : <div />} | ||
{text} | ||
</button> | ||
) | ||
} | ||
|
||
interface SelectProps { | ||
value: string | ||
options: string[] | ||
onSelect: (value: string) => void | ||
} | ||
|
||
const Select = ({ value, options, onSelect }: SelectProps) => { | ||
const [isOpen, setIsOpen] = useState(false) | ||
|
||
const onSelectItem = (selectedValue: string) => { | ||
onSelect(selectedValue) | ||
setIsOpen(false) | ||
} | ||
|
||
return ( | ||
<div className="relative"> | ||
<button | ||
className={`flex h-12 w-full items-center justify-between rounded-md border ${isOpen ? 'border-gray-400' : 'border-gray-800'} px-3.5`} | ||
type="button" | ||
onClick={() => setIsOpen((prev) => !prev)} | ||
> | ||
<span>{value}</span> | ||
{isOpen ? <ArrowDownIcon /> : <ArrowUpIcon />} | ||
</button> | ||
{isOpen && ( | ||
<div className="absolute left-0 top-12 z-10 mt-1 flex w-full flex-col rounded-md border border-gray-400 bg-gray-0"> | ||
{options.map((option) => ( | ||
<SelectOption | ||
key={option} | ||
text={option} | ||
selected={value === option} | ||
onSelect={onSelectItem} | ||
/> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default Select |
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,54 @@ | ||
'use client' | ||
|
||
import { ChangeEvent, useRef } from 'react' | ||
import { twMerge } from 'tailwind-merge' | ||
|
||
interface TextInputProps { | ||
value: string | ||
setValue: (value: string) => void | ||
hasError: boolean | ||
description: string | ||
errorMessage: string | ||
placeholder: string | ||
} | ||
|
||
const TextInput = ({ | ||
value, | ||
setValue, | ||
hasError, | ||
description, | ||
errorMessage, | ||
placeholder, | ||
}: TextInputProps) => { | ||
const borderClass = twMerge( | ||
'flex items-center mb-2 border-b ', | ||
hasError ? 'border-negative' : 'border-gray-950', | ||
) | ||
const textareaRef = useRef<HTMLTextAreaElement>(null) | ||
|
||
return ( | ||
<div className={`w-full ${hasError ? 'text-negative' : ''}`}> | ||
<div className={borderClass}> | ||
<textarea | ||
placeholder={placeholder} | ||
ref={textareaRef} | ||
rows={1} | ||
value={value} | ||
onChange={(e: ChangeEvent<HTMLTextAreaElement>) => { | ||
if (textareaRef.current) { | ||
textareaRef.current.style.height = 'auto' | ||
textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px` | ||
} | ||
setValue(e.target.value) | ||
}} | ||
className="w-full resize-none overflow-y-hidden bg-transparent p-1 outline-none" | ||
/> | ||
</div> | ||
<div className="text-right text-xs"> | ||
{hasError ? errorMessage : description} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default TextInput |
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,8 @@ | ||
import { put } from '@/lib/api/base' | ||
import { WithdrawUserPayload } from '@/types' | ||
|
||
export const withdraw = async (body: WithdrawUserPayload) => { | ||
return put('/api/v1/user/withdraw', { | ||
body: JSON.stringify(body), | ||
}) | ||
} |
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,4 @@ | ||
export type WithdrawUserPayload = { | ||
type: string | ||
reason: string | ||
} |