Skip to content

Commit 27d0e81

Browse files
cgokeyChristopher D. Gokey
andauthored
MMT-4080: Moved everything into one useEffect
Co-authored-by: Christopher D. Gokey <christopher.d.gokey@nasa.gov>
1 parent 7b3351f commit 27d0e81

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

static/src/js/components/PermissionForm/PermissionForm.jsx

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,6 @@ const PermissionForm = ({ selectedCollectionsPageSize }) => {
213213
}
214214
}, [providerIds])
215215

216-
useEffect(() => {
217-
formData.providers = providerId
218-
setFormData((prevFormData) => ({
219-
...prevFormData,
220-
providers: providerId
221-
}))
222-
}, [providerId])
223-
224216
const [createAclMutation] = useMutation(CREATE_ACL)
225217
const [updateAclMutation] = useMutation(UPDATE_ACL, {
226218
update: (cache) => {
@@ -306,12 +298,6 @@ const PermissionForm = ({ selectedCollectionsPageSize }) => {
306298
})
307299
}, [data])
308300

309-
useEffect(() => {
310-
if (conceptId === 'new') {
311-
setFormData({ ...initFormState })
312-
}
313-
}, [conceptId])
314-
315301
useEffect(() => {
316302
if (error) {
317303
throw error
@@ -363,7 +349,6 @@ const PermissionForm = ({ selectedCollectionsPageSize }) => {
363349

364350
// When 'data' is available, this block generates formData using information from the ACL from CMR.
365351
useEffect(() => {
366-
console.log('data is ', data)
367352
if (data) {
368353
const { acl } = data
369354
const {
@@ -518,11 +503,19 @@ const PermissionForm = ({ selectedCollectionsPageSize }) => {
518503

519504
return {
520505
...prevFormData,
521-
...updatedFormData
506+
...updatedFormData,
507+
providers: providerId // Use the latest providerId
522508
}
523509
})
510+
} else if (conceptId === 'new') {
511+
// Handle the case for new permissions
512+
setFormData((prevFormData) => ({
513+
...prevFormData,
514+
...initFormState,
515+
providers: providerId
516+
}))
524517
}
525-
}, [data])
518+
}, [data, providerId, conceptId])
526519

527520
const totalSelectedCollections = () => {
528521
const {

0 commit comments

Comments
 (0)