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

Feat/preview modal #26

Merged
merged 2 commits into from
Aug 20, 2023
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
2 changes: 2 additions & 0 deletions src/features/login/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export type User = {
companyNo?: string;
department?: string;
position?: string;
comment?: string;
mood?: string;
};
export type DummyUser = User & { password?: string };

Expand Down
2 changes: 1 addition & 1 deletion src/features/preview/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Container = () => {

useLayoutEffect(() => {
setTitle({ title: 'CardMe Preview', back: true });
setBottomBtn({ text: 'Modification', disable: curNum !== 1 });
setBottomBtn({ text: 'Edit', disable: curNum !== 1 });

return () => {
setTitle({});
Expand Down
19 changes: 17 additions & 2 deletions src/features/setting/hooks/useSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,26 @@ import badMood from '/png/badge_bad.png';

import { dummyEsl, labelsImagePushPath, token } from '../constants';
import { modalAtom } from '../../shared/modal/atom';
import { userAtom } from '../../login/atom';

const useSetting = () => {
const [, setModal] = useAtom(modalAtom);
const [, setPreviewMood] = useAtom(previewMoodAtom);
const [{ mood, comment }, setUser] = useAtom(userAtom);
const { register, handleSubmit, control, formState } = useForm<Inputs>({
defaultValues: {
mood: mood,
comment: comment,
},
});

const { register, handleSubmit, control, formState } = useForm<Inputs>();
const onSubmit: SubmitHandler<Inputs> = async (data) => {
const imgEl = document.createElement('img');
setUser((prev) => ({
...prev,
mood: data.mood,
comment: data.comment,
}));
imgEl.src = data.mood === 'mood_GOOD' ? goodMood : badMood; //TODO ์ด๋ž˜๋„ ๋ ๊นŒ

fetch(imgEl.src)
Expand All @@ -39,7 +51,10 @@ const useSetting = () => {
};

const handlePreviewClick = () => {
setPreviewMood((prev) => ({ ...prev, open: true }));
setPreviewMood((prev) => ({
value: mood ? mood.slice(5) : prev.value,
open: true,
}));
setModal({ open: true });
};

Expand Down
14 changes: 13 additions & 1 deletion src/features/shared/layout/components/BottomBtn.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
import { useAtom } from 'jotai';
import { FunctionComponent } from 'react';
import { useNavigate } from 'react-router-dom';

import { activeSaveAtom, bottomBtnAtom } from '../atom';

import addLogo from '/svg/add.svg';

import { URL } from '../../constants/url';

const LayoutBottomBtn: FunctionComponent = () => {
const [{ text, add, disable }] = useAtom(bottomBtnAtom);
const [, setActiveSave] = useAtom(activeSaveAtom);
const navigate = useNavigate();

const handleBtnClick = () => {
if (text === 'Edit') {
navigate(URL.setting);
} else if (text === 'Save') {
setActiveSave(true);
}
};

if (!text) return null;

return (
<div className="layout-bottom">
<button
className="layout-bottom-btn"
onClick={() => setActiveSave(true)}
onClick={handleBtnClick}
disabled={disable}
>
<div className="left">
Expand Down
16 changes: 11 additions & 5 deletions src/features/shared/modal/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useResetAtom } from 'jotai/utils';
import win from '/svg/win.svg';
import next from '/svg/next.svg';
import idCard from '/svg/idcard_basic.svg';
import moodBad from '/png/mood_BAD.png';
import moodGood from '/png/mood_GOOD.png';

import { previewMoodAtom } from '../layout/atom';

Expand All @@ -12,10 +14,9 @@ import './modal.scss';

const ModalContainer = () => {
const [modal] = useAtom(modalAtom);
const [previewMood] = useAtom(previewMoodAtom);
const [previewMood, setPreviewMood] = useAtom(previewMoodAtom);
const resetModal = useResetAtom(modalAtom);

console.log(previewMood);
if (!modal.open) return null;
const { imageType, onClose, title, description, footer, onConfirm } =
modal as Modal;
Expand All @@ -33,25 +34,30 @@ const ModalContainer = () => {
const handleCloseClick = () => {
onClose?.();
resetModal();
setPreviewMood({ open: false });
};
const handleConfirmClick = () => {
onConfirm?.();
resetModal();
};
console.log(previewMood);
return (
<div className="modal-container">
<div className="content">
<span className="close-btn" onClick={handleCloseClick}>
&times;
</span>
{previewMood.open || modal.open ? (
{previewMood.open && modal.open ? (
<>
<div className="modal-preview-title">Preview</div>
<div className="modal-preview-box">
<img src={idCard} alt="preview" />
<div className="modal-sticker-picked">
<img src={`/png/mood_${previewMood.value}.png`} alt="preview" />
{previewMood.value === 'GOOD' && (
<img src={moodGood} alt="preview" />
)}
{previewMood.value === 'BAD' && (
<img src={moodBad} alt="preview" />
)}
</div>
</div>
</>
Expand Down