File tree Expand file tree Collapse file tree 4 files changed +16
-4
lines changed Expand file tree Collapse file tree 4 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -8,8 +8,9 @@ import DialogTitle from '@mui/material/DialogTitle';
88import SaveOutlinedIcon from '@mui/icons-material/SaveOutlined' ;
99import { saveProject } from '../../helperFunctions/projectGetSaveDel' ;
1010import { useDispatch , useSelector } from 'react-redux'
11- import { updateProjectName } from '../../redux/reducers/slice/appStateSlice' ;
11+ import { updateProjectName , updateProjectId } from '../../redux/reducers/slice/appStateSlice' ;
1212import { RootState } from '../../redux/store' ;
13+ import { State } from '../../interfaces/Interfaces' ;
1314
1415export default function FormDialog ( ) {
1516 const [ open , setOpen ] = useState ( false ) ;
@@ -34,7 +35,7 @@ const dispatch = useDispatch();
3435 // If errors occur on the backend, the project name still gets updated
3536
3637 dispatch ( updateProjectName ( projectName ) )
37- saveProject ( projectName , state ) . then ( ( project ) => { console . log ( project ) } )
38+ saveProject ( projectName , state ) . then ( ( project : State ) => dispatch ( updateProjectId ( project . _id ) ) ) //updates the slice with new _id from mongo
3839 setOpen ( false ) ;
3940 } else {
4041 setInvalidProjectName ( true ) ;
Original file line number Diff line number Diff line change 1+ import { State } from "../interfaces/Interfaces" ;
2+
13const isDev = process . env . NODE_ENV === 'development' ;
24const { DEV_PORT , API_BASE_URL } = require ( '../../../config.js' ) ;
35let serverURL = API_BASE_URL ;
@@ -31,9 +33,11 @@ export const saveProject = (
3133 name : String ,
3234 workspace : Object
3335) : Promise < Object > => {
36+ const newProject = { ...workspace }
37+ delete newProject [ '_id' ] ; //deleting the _id from the current state slice. We don't actually want it in the project object in the mongo db document
3438 const body = JSON . stringify ( {
3539 name,
36- project : { ...workspace , name } ,
40+ project : { ...newProject , name } ,
3741 userId : window . localStorage . getItem ( 'ssid' ) ,
3842 username : window . localStorage . getItem ( 'username' ) ,
3943 comments : [ ]
@@ -48,7 +52,7 @@ export const saveProject = (
4852 } )
4953 . then ( ( res ) => res . json ( ) )
5054 . then ( ( data ) => {
51- return { _id : data . _id , ...data . project } ;
55+ return { _id : data . _id , ...data . project } ; //passing up what is needed for the global appstateslice
5256 } )
5357 . catch ( ( err ) => console . log ( `Error saving project ${ err } ` ) ) ;
5458 return project ; //returns _id in addition to the project object from the document
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { DragObjectWithType } from 'react-dnd';
22
33export interface State {
44 name : string ;
5+ _id : string ;
56 forked : boolean ;
67 isLoggedIn : boolean ;
78 components : Component [ ] ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import manageSeparators from '../../../helperFunctions/manageSeparators';
1313
1414export const initialState : State = {
1515 name : '' ,
16+ _id : '' ,
1617 forked : false ,
1718 isLoggedIn : false ,
1819 // config: { saveFlag: true, saveTimer: false },
@@ -770,6 +771,10 @@ const appStateSlice = createSlice({
770771 const projectName = action . payload ;
771772 state . name = projectName ;
772773 } ,
774+ updateProjectId : ( state , action ) => {
775+ const projectId = action . payload ; //updates the slice with new _id
776+ state . _id = projectId ;
777+ } ,
773778 deleteElement : ( state , action ) => {
774779 let name : string = '' ;
775780 const HTMLTypes : HTMLType [ ] = [ ...state . HTMLTypes ] . filter ( ( el ) => {
@@ -1292,6 +1297,7 @@ export const {
12921297 changeProjectType,
12931298 resetState,
12941299 updateProjectName,
1300+ updateProjectId,
12951301 deleteElement,
12961302 updateAttributes,
12971303 deleteChild,
You can’t perform that action at this time.
0 commit comments