11import React , { useState } from 'react' ;
2+ import { toast } from 'react-toastify' ;
23import axios from 'axios' ;
34import Modal from './ParentModal' ;
45import { actionType as T } from '../../reducer' ;
@@ -14,19 +15,23 @@ const ContributeDetails = ({ superState, dispatcher }) => {
1415 const [ title , setTitle ] = useState ( '' ) ;
1516 const [ desc , setDesc ] = useState ( '' ) ;
1617 const [ branch , setBranch ] = useState ( '' ) ;
18+ const [ showAdvanceOptions , setShowAdvanceOptions ] = useState ( false ) ;
1719 const submit = async ( e ) => {
20+ const id = toast . loading ( 'Processing Your Request.Please wait...' ) ;
1821 try {
1922 e . preventDefault ( ) ;
2023 const result = await axios . post ( `http://127.0.0.1:5000/contribute?study=${ study } &auth=${ auth } &desc=${ desc } &title=${ title } &path=${ path } &branch=${ branch } ` , { token : process . env . TOKEN } ) ;
2124 // eslint-disable-next-line
22- console . log ( process . env . Token ) ;
23- // eslint-disable-next-line
24- alert ( result . data . message ) ;
25- // console.log(result.data);
26- closeModal ( ) ;
25+ // console.log(process.env.Token);
26+ toast . success ( result . data ?. message ) ;
2727 } catch ( error ) {
28- // console.log (error);
28+ toast . error ( error . response . data . message ) ;
2929 }
30+ toast . dismiss ( id ) ;
31+ closeModal ( ) ;
32+ } ;
33+ const toggleOptions = ( ) => {
34+ setShowAdvanceOptions ( ! showAdvanceOptions ) ;
3035 } ;
3136 return (
3237 < Modal
@@ -60,18 +65,26 @@ const ContributeDetails = ({ superState, dispatcher }) => {
6065 onChange = { ( e ) => setBranch ( e . target . value ) }
6166 required
6267 />
63- < span > PR Title</ span >
64- < input
65- value = { title }
66- onChange = { ( e ) => setTitle ( e . target . value ) }
67- required
68- />
69- < span > PR Description</ span >
70- < input
71- value = { desc }
72- onChange = { ( e ) => setDesc ( e . target . value ) }
73- required
74- />
68+ { showAdvanceOptions && (
69+ < >
70+ < span > PR Title</ span >
71+ < input
72+ value = { title }
73+ onChange = { ( e ) => setTitle ( e . target . value ) }
74+ required
75+ />
76+ < span > PR Description</ span >
77+ < input
78+ value = { desc }
79+ onChange = { ( e ) => setDesc ( e . target . value ) }
80+ required
81+ />
82+ </ >
83+ ) }
84+ < button type = "button" className = "btn btn-secondary" onClick = { toggleOptions } >
85+ { showAdvanceOptions ? 'Hide ' : 'Show ' }
86+ Advance Options
87+ </ button >
7588 < div className = "expand" >
7689 < button type = "submit" className = "btn btn-primary" onClick = { submit } > Generate PR</ button >
7790 </ div >
0 commit comments