Skip to content

Commit 21f2f94

Browse files
committed
auto-fill Contribute form from active graph metadata
1 parent eccddfd commit 21f2f94

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/component/modals/ContributeDetails.jsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import { toast } from 'react-toastify';
33
import axios from 'axios';
44
import { EXECUTION_ENGINE_URL } from '../../serverCon/config';
@@ -10,13 +10,25 @@ const ContributeDetails = ({ superState, dispatcher }) => {
1010
const closeModal = () => {
1111
dispatcher({ type: T.SET_CONTRIBUTE_MODAL, payload: false });
1212
};
13-
const [study, setStudy] = useState('');
14-
const [path, setPath] = useState('');
15-
const [auth, setAuth] = useState('');
13+
14+
const curGraph = superState.graphs[superState.curGraphIndex] ?? {};
15+
16+
const [study, setStudy] = useState(curGraph.projectName ?? '');
17+
const [path, setPath] = useState(superState.uploadedDirName ?? '');
18+
const [auth, setAuth] = useState(curGraph.authorName ?? '');
1619
const [title, setTitle] = useState('');
1720
const [desc, setDesc] = useState('');
1821
const [branch, setBranch] = useState('');
1922
const [showAdvanceOptions, setShowAdvanceOptions] = useState(false);
23+
24+
useEffect(() => {
25+
if (superState.contributeModal) {
26+
const activeGraph = superState.graphs[superState.curGraphIndex] ?? {};
27+
setStudy(activeGraph.projectName ?? '');
28+
setPath(superState.uploadedDirName ?? '');
29+
setAuth(activeGraph.authorName ?? '');
30+
}
31+
}, [superState.contributeModal]);
2032
const submit = async (e) => {
2133
if (study === '' || path === '' || auth === '') {
2234
toast.info('Please Provide necessary inputs');

0 commit comments

Comments
 (0)