Skip to content

Commit

Permalink
refactor: saveTemporary 함수를 컴포넌트에서 분리
Browse files Browse the repository at this point in the history
- 스터디와 모집 공고 두 경우에서 전부 사용할 수 있음
- 컴포넌트 밖으로 함수를 분리하여 렌덜이 성능 개선 및 기능 분리
  • Loading branch information
abiriadev committed Apr 24, 2024
1 parent 1861440 commit de6fd71
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/Pages/CreateRecruitment/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Modal from '@/Components/Common/Modal';
import StackModal from '@/Components/Modal/StackModal';
import { Label } from '@/Components/Selectbox/SelectBox';
import { useSelectDefaultValue } from '@/Hooks/recruitments/useSelectDefaultValue';
import { saveTemporary } from '@/utils/temporarySavedUtils';

const DEF_VAL = 'ex. Typescript';

Expand Down Expand Up @@ -89,12 +90,6 @@ const CreateRecruitmentPage = () => {

const data = watch();

const saveTemporary = (savedKey: string) => {
if (savedKey.length > 0) localStorage.removeItem(savedKey);
const newSavedKey = `RECRUITMENT-${studyId}-${uuidv1()}`;
localStorage.setItem(newSavedKey, JSON.stringify({ ...data, stackIds: selectedStacks }));
};

const [isOpen, setIsOpen] = useState<boolean>(false);
const [selectedStacks, setSelectedStacks] = useState<StackType[] | null>(null);
const [content, setContent] = useState(DEF_VAL);
Expand All @@ -113,7 +108,7 @@ const CreateRecruitmentPage = () => {
<Modal
handleApprove={() => {
closeModal();
saveTemporary(savedKey);
saveTemporary(savedKey, 'RECRUITMENT', { ...data, stackIds: selectedStacks });
}}
cancelBtnText="취소하기"
title="작성 중인 스터디 생성 글을 임시 저장 하시겠습니까?"
Expand Down
5 changes: 5 additions & 0 deletions src/utils/temporarySavedUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const saveTemporary = (savedKey: string, type: 'STUDY' | 'RECRUITMENT', data: unknown) => {
if (savedKey.length > 0) localStorage.removeItem(savedKey);
const newSavedKey = `${type}-${studyId}-${uuidv1()}`;
localStorage.setItem(newSavedKey, JSON.stringify(data));
};

0 comments on commit de6fd71

Please sign in to comment.