diff --git a/.gitignore b/.gitignore index 991180bab1..705062d436 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ functions/firebase-debug.log .pnp.* *.tsbuildinfo +supabase/.branches +supabase/.temp +supabase/.env diff --git a/src/pages/Research/Content/Common/Research.form.tsx b/src/pages/Research/Content/Common/Research.form.tsx index d77b303d8f..38342b4d02 100644 --- a/src/pages/Research/Content/Common/Research.form.tsx +++ b/src/pages/Research/Content/Common/Research.form.tsx @@ -74,25 +74,12 @@ const ResearchForm = observer((props: IProps) => { const store = useResearchStore() const [showSubmitModal, setShowSubmitModal] = useState(false) - const [submissionHandler, setSubmissionHandler] = useState({ + const [submissionHandler, setSubmissionHandler] = useState(() => ({ draft: formValues.moderation === IModerationStatus.DRAFT, shouldSubmit: false, - }) + })) const [slug, setSlug] = useState('') - // Managing locked state - useEffect(() => { - if (store.activeUser && props.research) { - store.lockResearchItem(props.research, store.activeUser.userName) - } - - return () => { - if (props.research) { - store.unlockResearchItem(props.research) - } - } - }, [store.activeUser]) - useEffect(() => { if (submissionHandler.shouldSubmit) { const form = document.getElementById('researchForm') @@ -105,11 +92,11 @@ const ResearchForm = observer((props: IProps) => { } }, [submissionHandler]) - const onSubmit = async (formValues: IResearch.FormInput) => { - formValues.moderation = submissionHandler.draft + const onSubmit = async (values: IResearch.FormInput) => { + values.moderation = submissionHandler.draft ? IModerationStatus.DRAFT : IModerationStatus.ACCEPTED // No moderation for researches for now - const updatedResearh = await store.uploadResearch(formValues) + const updatedResearh = await store.uploadResearch(values) if (updatedResearh) { setSlug(updatedResearh.slug) diff --git a/src/pages/Research/Content/Common/ResearchUpdate.form.tsx b/src/pages/Research/Content/Common/ResearchUpdate.form.tsx index e3c88e361e..e91114206b 100644 --- a/src/pages/Research/Content/Common/ResearchUpdate.form.tsx +++ b/src/pages/Research/Content/Common/ResearchUpdate.form.tsx @@ -71,26 +71,6 @@ export const ResearchUpdateForm = observer((props: IProps) => { } }, [store.updateUploadStatus?.Complete]) - // Managing locked state - useEffect(() => { - if (store.activeUser) - store.toggleLockResearchUpdate( - props.research._id, - store.activeUser.userName, - formValues._id, - true, - ) - - return () => { - store.toggleLockResearchUpdate( - props.research._id, - '', - formValues._id, - false, - ) - } - }, [store.activeUser]) - const trySubmitForm = (isDraft: boolean) => { const form = document.getElementById('updateForm') setIsDraft(isDraft) diff --git a/src/stores/Research/research.store.tsx b/src/stores/Research/research.store.tsx index 512a573530..7568b3d196 100644 --- a/src/stores/Research/research.store.tsx +++ b/src/stores/Research/research.store.tsx @@ -44,8 +44,6 @@ export class ResearchStore extends ModuleStore { updateUpdateUploadStatus: action, resetResearchUploadStatus: action, resetUpdateUploadStatus: action, - lockResearchItem: action, - unlockResearchItem: action, }) } @@ -380,64 +378,6 @@ export class ResearchStore extends ModuleStore { } } - public async lockResearchItem(item: IResearchDB, username: string) { - if (item) { - const dbRef = this.db - .collection(COLLECTION_NAME) - .doc(item._id) - const newItem = { - ...item, - locked: { - by: username, - at: new Date().toISOString(), - }, - } - await this._updateResearchItem(dbRef, newItem) - } - } - - public async unlockResearchItem(item: IResearchDB) { - if (item) { - const dbRef = this.db - .collection(COLLECTION_NAME) - .doc(item._id) - const newItem = { - ...item, - locked: null, - } - await this._updateResearchItem(dbRef, newItem) - } - } - - public async toggleLockResearchUpdate( - researchId: string, - username: string, - updateId: string, - lock: boolean, - ) { - const dbRef = this.db - .collection(COLLECTION_NAME) - .doc(researchId) - - const item = toJS(await dbRef.get('server')) as IResearchDB - const updateIndex = item.updates.findIndex((upd) => upd._id === updateId) - const updatedItem = { - ...item, - updates: [...item.updates], - } - - if (updatedItem.updates[updateIndex]) { - updatedItem.updates[updateIndex].locked = lock - ? { - by: username, - at: new Date().toISOString(), - } - : null - } - - await dbRef.set(updatedItem) - } - private async _setCollaborators( collaborators: IResearch.Item['collaborators'] | string | undefined, ) {