Skip to content

Commit

Permalink
feat(active): change word, save active data in user
Browse files Browse the repository at this point in the history
  • Loading branch information
anyl92 committed Aug 20, 2023
1 parent a573002 commit d4e6fcf
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
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

0 comments on commit d4e6fcf

Please sign in to comment.