|
| 1 | +import { useEffect, useState } from "react"; |
| 2 | +import Button from "../commons/button"; |
| 3 | +import { Dialog } from "../commons/dialog"; |
| 4 | +import { Compact } from "@uiw/react-color"; |
| 5 | +import useUserStore from "@/store/useUserStore"; |
| 6 | + |
| 7 | +type RemoveNoteModalProps = { |
| 8 | + isOpen: boolean; |
| 9 | + onConfirm: () => void; |
| 10 | + onCloseModal: () => void; |
| 11 | +}; |
| 12 | + |
| 13 | +export default function ProfileModal({ |
| 14 | + isOpen, |
| 15 | + onConfirm, |
| 16 | + onCloseModal, |
| 17 | +}: RemoveNoteModalProps) { |
| 18 | + const { currentUser, setCurrentUser, provider } = useUserStore(); |
| 19 | + const [hex, setHex] = useState(currentUser.color); |
| 20 | + const [isColorPickerOpen, setIsColorPickerOpen] = useState(false); |
| 21 | + const [nickname, setNickname] = useState(currentUser.clientId); |
| 22 | + |
| 23 | + useEffect(() => { |
| 24 | + setNickname(currentUser.clientId); |
| 25 | + setHex(currentUser.color); |
| 26 | + }, [currentUser]); |
| 27 | + |
| 28 | + return ( |
| 29 | + <Dialog isOpen={isOpen} onCloseModal={onCloseModal}> |
| 30 | + <div className="flex flex-col items-center gap-4"> |
| 31 | + <div className="flex flex-col items-center gap-1.5"> |
| 32 | + <Dialog.Title>프로필 수정</Dialog.Title> |
| 33 | + </div> |
| 34 | + <div className="flex flex-row items-center gap-3"> |
| 35 | + <button |
| 36 | + className="h-12 w-12 rounded-full border-[1px] border-black" |
| 37 | + style={{ backgroundColor: hex }} |
| 38 | + onClick={() => setIsColorPickerOpen(!isColorPickerOpen)} |
| 39 | + /> |
| 40 | + |
| 41 | + <input |
| 42 | + className={ |
| 43 | + "h-10 rounded-md border-[1px] border-[#eaeaea] p-2 text-sm text-[#141414] outline-none" |
| 44 | + } |
| 45 | + placeholder="닉네임을 입력하세요" |
| 46 | + value={nickname} |
| 47 | + onChange={(e) => setNickname(e.target.value)} |
| 48 | + /> |
| 49 | + </div> |
| 50 | + <div className=""> |
| 51 | + {isColorPickerOpen && ( |
| 52 | + <Compact color={hex} onChange={(color) => setHex(color.hex)} /> |
| 53 | + )} |
| 54 | + </div> |
| 55 | + |
| 56 | + <div className="flex w-full flex-row justify-between gap-2"> |
| 57 | + <Button |
| 58 | + className="w-full rounded-lg bg-[#171717] text-neutral-100 hover:bg-slate-800" |
| 59 | + onClick={() => { |
| 60 | + provider.awareness.setLocalStateField("color", hex); |
| 61 | + provider.awareness.setLocalStateField("clientId", nickname); |
| 62 | + |
| 63 | + setCurrentUser({ |
| 64 | + ...currentUser, |
| 65 | + color: hex, |
| 66 | + clientId: nickname, |
| 67 | + }); |
| 68 | + |
| 69 | + onConfirm(); |
| 70 | + }} |
| 71 | + > |
| 72 | + 확인 |
| 73 | + </Button> |
| 74 | + <Button |
| 75 | + className="w-full rounded-lg bg-[#f4f4f5] text-neutral-700 hover:bg-neutral-200" |
| 76 | + onClick={onCloseModal} |
| 77 | + > |
| 78 | + 취소 |
| 79 | + </Button> |
| 80 | + </div> |
| 81 | + </div> |
| 82 | + <Dialog.CloseButton onCloseModal={onCloseModal} /> |
| 83 | + </Dialog> |
| 84 | + ); |
| 85 | +} |
0 commit comments