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';
8
8
import SaveOutlinedIcon from '@mui/icons-material/SaveOutlined' ;
9
9
import { saveProject } from '../../helperFunctions/projectGetSaveDel' ;
10
10
import { useDispatch , useSelector } from 'react-redux'
11
- import { updateProjectName } from '../../redux/reducers/slice/appStateSlice' ;
11
+ import { updateProjectName , updateProjectId } from '../../redux/reducers/slice/appStateSlice' ;
12
12
import { RootState } from '../../redux/store' ;
13
+ import { State } from '../../interfaces/Interfaces' ;
13
14
14
15
export default function FormDialog ( ) {
15
16
const [ open , setOpen ] = useState ( false ) ;
@@ -34,7 +35,7 @@ const dispatch = useDispatch();
34
35
// If errors occur on the backend, the project name still gets updated
35
36
36
37
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
38
39
setOpen ( false ) ;
39
40
} else {
40
41
setInvalidProjectName ( true ) ;
Original file line number Diff line number Diff line change
1
+ import { State } from "../interfaces/Interfaces" ;
2
+
1
3
const isDev = process . env . NODE_ENV === 'development' ;
2
4
const { DEV_PORT , API_BASE_URL } = require ( '../../../config.js' ) ;
3
5
let serverURL = API_BASE_URL ;
@@ -31,9 +33,11 @@ export const saveProject = (
31
33
name : String ,
32
34
workspace : Object
33
35
) : 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
34
38
const body = JSON . stringify ( {
35
39
name,
36
- project : { ...workspace , name } ,
40
+ project : { ...newProject , name } ,
37
41
userId : window . localStorage . getItem ( 'ssid' ) ,
38
42
username : window . localStorage . getItem ( 'username' ) ,
39
43
comments : [ ]
@@ -48,7 +52,7 @@ export const saveProject = (
48
52
} )
49
53
. then ( ( res ) => res . json ( ) )
50
54
. 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
52
56
} )
53
57
. catch ( ( err ) => console . log ( `Error saving project ${ err } ` ) ) ;
54
58
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';
2
2
3
3
export interface State {
4
4
name : string ;
5
+ _id : string ;
5
6
forked : boolean ;
6
7
isLoggedIn : boolean ;
7
8
components : Component [ ] ;
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import manageSeparators from '../../../helperFunctions/manageSeparators';
13
13
14
14
export const initialState : State = {
15
15
name : '' ,
16
+ _id : '' ,
16
17
forked : false ,
17
18
isLoggedIn : false ,
18
19
// config: { saveFlag: true, saveTimer: false },
@@ -770,6 +771,10 @@ const appStateSlice = createSlice({
770
771
const projectName = action . payload ;
771
772
state . name = projectName ;
772
773
} ,
774
+ updateProjectId : ( state , action ) => {
775
+ const projectId = action . payload ; //updates the slice with new _id
776
+ state . _id = projectId ;
777
+ } ,
773
778
deleteElement : ( state , action ) => {
774
779
let name : string = '' ;
775
780
const HTMLTypes : HTMLType [ ] = [ ...state . HTMLTypes ] . filter ( ( el ) => {
@@ -1292,6 +1297,7 @@ export const {
1292
1297
changeProjectType,
1293
1298
resetState,
1294
1299
updateProjectName,
1300
+ updateProjectId,
1295
1301
deleteElement,
1296
1302
updateAttributes,
1297
1303
deleteChild,
You can’t perform that action at this time.
0 commit comments