@@ -23,11 +23,10 @@ function LessonForm() {
2323 const roles = useSelector ( state => state . role . roles ) ; // grab all roles from store
2424 // const projects = useSelector(state => state.allProjects.projects); // grab all projects from store(not BM projects)
2525 const projects = useSelector ( state => state . bmProjects ) ; // grab all BM projects from store
26- const [ LessonFormtags , setLessonFormTags ] = useState ( [ 'Building 1' , 'Building 2' , 'Building 3' ] ) ; // save all tags user inputs
27- const [ permanentTags , setPermanentTags ] = useState ( [ 'Building 1' , 'Building 2' , 'Building 3' ] ) ;
26+ const [ LessonFormtags , setLessonFormTags ] = useState ( [ ] ) ; // save all tags user inputs
27+ const [ permanentTags , setPermanentTags ] = useState ( [ ] ) ;
2828 const [ tagInput , setTagInput ] = useState ( '' ) ; // track user input in tag input
2929 const [ selectedFile , setSelectedFile ] = useState ( null ) ; // track file that was selected or droped in upload appendix
30- const [ prevselectedProject , setprevSelectedProject ] = useState ( null ) ; // used to track the previously project selected for deletion in tags when changed
3130 const [ selectedProject , setSelectedProject ] = useState ( null ) ; // Track selected project in Belongs to dropdown
3231 const [ selectedRole , setSelectedRole ] = useState ( 'All' ) ; // track selected role in View by dropdown
3332 const [ LessonText , setLessonText ] = useState ( null ) ; // track lesson text
@@ -89,12 +88,6 @@ function LessonForm() {
8988 const newTags = LessonFormtags . filter ( tag => tag !== tagToRemove ) ;
9089 setLessonFormTags ( newTags ) ;
9190 } ;
92- // removes the previously added project from tags if a new one is selected from belongs to dropdown
93- const removePreviousProject = prevproject => {
94- const newTags = LessonFormtags . filter ( project => project !== prevproject ) ;
95- setLessonFormTags ( newTags ) ;
96- } ;
97-
9891 const fetchTags = async ( ) => {
9992 try {
10093 const response = await axios . get ( ENDPOINTS . BM_TAGS ) ;
@@ -137,7 +130,6 @@ function LessonForm() {
137130 // Set the project name as a tag
138131 setProjectName ( foundProject . name ) ;
139132 setSelectedProject ( projectId ) ;
140- setLessonFormTags ( [ projectname ] ) ;
141133 }
142134 }
143135 } , [ projectId , projects ] ) ;
@@ -193,38 +185,10 @@ function LessonForm() {
193185 const lessonformtitleinput = e . target . value ;
194186 setLessonTitleText ( lessonformtitleinput ) ;
195187 } ;
196- useEffect ( ( ) => {
197- if ( selectedProject && prevselectedProject !== selectedProject ) {
198- // Find the project with the selected ID
199- const foundProject = projects . find ( project => project . _id === selectedProject ) ;
200- // Check if the found project is valid
201- if ( foundProject ) {
202- setprevSelectedProject ( selectedProject ) ;
203- // Remove the tag for the previously selected project
204- if ( prevselectedProject ) {
205- removePreviousProject (
206- projects . find ( project => project . _id === prevselectedProject ) ?. name ,
207- ) ;
208- }
209- // Add the project name to the tags array
210- setLessonFormTags ( tags => [ ...tags , foundProject . name ] ) ;
211- }
212- }
213- } , [ selectedProject , prevselectedProject , projects ] ) ;
214188
215189 // Lesson submit. all the data from user input is in here
216190 const LessonFormSubmit = async e => {
217191 e . preventDefault ( ) ;
218- // console.log(LessonFormtags, "Tags")
219- // console.log(selectedProject, "selected project")
220- // console.log(selectedRole, "selecedRole")
221- // console.log(selectedFile, "selected file")
222- // console.log(LessonText, "lesson text")
223- // console.log(LessonTitleText,"lesson title")
224- if ( ! LessonFormtags . length ) {
225- toast . info ( 'Need atleast one tag' ) ;
226- return ;
227- }
228192 if ( ! selectedProject ) {
229193 toast . info ( 'Need to select a project' ) ;
230194 return ;
0 commit comments