Skip to content

Commit

Permalink
Merge pull request #277 from mash-up-kr/fix/editor
Browse files Browse the repository at this point in the history
모집공고 에디터 QA 반영
  • Loading branch information
sanoopark committed Jul 29, 2023
2 parents 26119d5 + 089fc25 commit c8f3f03
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/components/common/Editor/Editor.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Editor = ({ id, savedData }: EditorProps) => {
const editorRef = useRef<EditorJS>();
const [editorData, setEditorData] = useState<OutputData>(savedData);
const [editorReady, setEditorReady] = useState(false);
const [isDataChanged, setIsDataChanged] = useState(false);

const initEditor = () => {
const editor = new EditorJS({
Expand All @@ -27,9 +28,10 @@ const Editor = ({ id, savedData }: EditorProps) => {
setEditorReady(true);
},
onChange: async () => {
const content = (await editorRef.current?.saver.save()) as OutputData;
localStorage.setItem(id, JSON.stringify(content));
setEditorData(content);
const newEditorData = (await editorRef.current?.saver.save()) as OutputData;
localStorage.setItem(id, JSON.stringify(newEditorData));
setEditorData(newEditorData);
if (editorData.time !== newEditorData.time) setIsDataChanged(true);
},
autofocus: true,
// @ts-expect-error: third party plugin
Expand Down Expand Up @@ -73,7 +75,7 @@ const Editor = ({ id, savedData }: EditorProps) => {
return (
<>
<div id={id} />;
<Blocker isBlocking={editorData.blocks?.length !== 0} />
<Blocker isBlocking={isDataChanged} />
</>
);
};
Expand Down
15 changes: 12 additions & 3 deletions src/pages/UpdatePlatformRecruit/UpdatePlatformRecruit.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { useRecoilValue } from 'recoil';
import { OutputData } from '@editorjs/editorjs';
import { Editor, EditorAside } from '@/components';
import * as Styled from './UpdatePlatformRecruit.styled';
import { $teams } from '@/store';
import { $teams, $profile } from '@/store';
import { SelectSize } from '@/components/common/Select/Select.component';
import { decodeHTMLEntities, getDefaultEditorData, removeWrongAmpString, request } from '@/utils';
import { useToast } from '@/hooks';
import { ToastType } from '@/components/common/Toast/Toast.component';
import * as api from '@/api';

const EDITOR_ID = 'platform-recruit-editor';
const STAFF_PROFILES = ['BRANDING', 'MASHUP'];

const UpdatePlatformRecruit = () => {
const [isLoading, setIsLoading] = useState(false);
Expand All @@ -25,6 +26,14 @@ const UpdatePlatformRecruit = () => {
label: name,
}));

const myTeamName = useRecoilValue($profile)[0];
const getTeamSelectOptions = () => {
if (STAFF_PROFILES.includes(myTeamName)) return teamOptions;
const myTeamOptionObject = teamOptions.find(({ label }) => label.toUpperCase() === myTeamName);
return [myTeamOptionObject ?? { label: '', value: '' }];
};
const teamSelectOptions = getTeamSelectOptions();

const handleUpdateButtonClick = async () => {
const originalOutputData = JSON.parse(localStorage.getItem(EDITOR_ID) ?? '{}');
const storageValue = { editorData: originalOutputData };
Expand Down Expand Up @@ -89,9 +98,9 @@ const UpdatePlatformRecruit = () => {
platform={
<Styled.TeamSelect
placeholder="플랫폼 선택"
defaultValue={teamOptions[0]}
defaultValue={teamSelectOptions[0]}
size={SelectSize.sm}
options={teamOptions}
options={teamSelectOptions}
onChangeOption={(option) => setSelectedPlatform(option.label.toLowerCase())}
/>
}
Expand Down

0 comments on commit c8f3f03

Please sign in to comment.