Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent validate function from recursive calls #8780

Merged
merged 5 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,26 @@ export function Review() {
const { setMetadata, getMetadata } = useEventMetadata()
const metadata = getMetadata(
eventId,
event.actions.find((a) => a.type === 'DECLARE')?.metadata
event.actions.find((a) => a.type === ActionType.REGISTER)?.metadata
)

const { eventConfiguration: config } = useEventConfiguration(event.type)

const formConfig = findActiveActionForm(config, ActionType.REGISTER)
if (!formConfig) {
throw new Error('No active form configuration found for declare action')
}

const setFormValues = useEventFormData((state) => state.setFormValuesIfEmpty)
const setFormValuesIfEmpty = useEventFormData(
(state) => state.setFormValuesIfEmpty
)
const getFormValues = useEventFormData((state) => state.getFormValues)
const previousFormValues = getCurrentEventState(event).data
const form = getFormValues(eventId)

useEffect(() => {
setFormValues(eventId, getCurrentEventState(event).data)
}, [event, eventId, setFormValues])

const form = getFormValues(eventId)
setFormValuesIfEmpty(eventId, previousFormValues)
}, [event, eventId, setFormValuesIfEmpty, previousFormValues])

async function handleEdit({
pageId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,37 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import React, { useEffect } from 'react'
import React, { useEffect, useState } from 'react'
import { useTypedParams } from 'react-router-typesafe-routes/dom'
import { useNavigate } from 'react-router-dom'
import { v4 as uuid } from 'uuid'
import { ROUTES } from '@client/v2-events/routes'
import { useEvents } from '@client/v2-events/features/events/useEvents/useEvents'

export function ValidateEvent() {
const [validated, setValidated] = useState(false)
const { eventId } = useTypedParams(ROUTES.V2.EVENTS.VALIDATE)
const navigate = useNavigate()

const events = useEvents()
const validateEvent = events.actions.validate

const transactionId = uuid()

useEffect(() => {
validateEvent.mutate({
eventId,
data: {},
transactionId: uuid(),
duplicates: []
})
navigate(ROUTES.V2.path)
}, [validateEvent, eventId, navigate])
if (!validated) {
validateEvent.mutate(
{
eventId,
data: {},
transactionId,
duplicates: []
},
{ onSettled: () => navigate(ROUTES.V2.path) }
)
setValidated(true)
}
}, [validateEvent, eventId, navigate, transactionId, validated])

return <div />
}
Loading