Skip to content

Commit

Permalink
BAI-1464 hook front-end UI to auto update request count on deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
PE39806 committed Oct 30, 2024
1 parent 71a7f8a commit 8b1cd1a
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useGetAccessRequestsForModelId,
} from 'actions/accessRequest'
import { useGetModel } from 'actions/model'
import { useGetReviewRequestsForUser } from 'actions/review'
import { useGetSchema } from 'actions/schema'
import { useGetCurrentUser } from 'actions/user'
import { useRouter } from 'next/router'
Expand Down Expand Up @@ -44,6 +45,7 @@ export default function EditableAccessRequestForm({
const { schema, isSchemaLoading, isSchemaError } = useGetSchema(accessRequest.schemaId)
const { isAccessRequestError, mutateAccessRequest } = useGetAccessRequest(accessRequest.modelId, accessRequest.id)
const { mutateAccessRequests } = useGetAccessRequestsForModelId(accessRequest.modelId)
const { mutateReviews } = useGetReviewRequestsForUser()
const { model, isModelLoading, isModelError } = useGetModel(accessRequest.modelId, EntryKind.MODEL)
const { currentUser, isCurrentUserLoading, isCurrentUserError } = useGetCurrentUser()

Expand All @@ -66,16 +68,17 @@ export default function EditableAccessRequestForm({
}, [accessRequest.metadata.overview.entities, currentUser, currentUserRoles])

const handleDeleteConfirm = useCallback(async () => {
setErrorMessage('')
setDeleteErrorMessage('')
const res = await deleteAccessRequest(accessRequest.modelId, accessRequest.id)
if (!res.ok) {
setDeleteErrorMessage(await getErrorMessage(res))
} else {
mutateAccessRequests()
mutateReviews()
setOpen(false)
router.push(`/model/${accessRequest.modelId}?tab=access`)
}
}, [mutateAccessRequests, accessRequest, router])
}, [accessRequest.modelId, accessRequest.id, mutateAccessRequests, mutateReviews, router])

async function handleSubmit() {
if (schema) {
Expand Down Expand Up @@ -122,6 +125,10 @@ export default function EditableAccessRequestForm({
resetForm()
}

function handleDelete() {
setOpen(true)
}

useEffect(() => {
resetForm()
}, [resetForm])
Expand Down Expand Up @@ -173,7 +180,7 @@ export default function EditableAccessRequestForm({
onEdit={handleEdit}
onCancel={handleCancel}
onSubmit={handleSubmit}
onDelete={() => setOpen(true)}
onDelete={handleDelete}
errorMessage={errorMessage}
showDeleteButton
/>
Expand Down

0 comments on commit 8b1cd1a

Please sign in to comment.