Skip to content

Improve ProgramForm validation to avoid duplicate backend requests #3977

@mrkeshav-05

Description

@mrkeshav-05

Is your feature request related to a problem? Please describe.
Currently, ProgramForm checks name uniqueness by making an additional query to the backend, which results in duplicate requests and duplicated validation logic. The backend already enforces uniqueness via GraphQL/database constraints, but frontend does not yet handle structured GraphQL validation errors.

  const checkNameUniquenessSync = useCallback(
    async (name: string): Promise<string | undefined> => {
      if (!name.trim()) {
        return undefined
      }

      try {
        const { data } = await client.query({
          query: GetMyProgramsDocument,
          variables: { search: name.trim(), page: 1, limit: 100 },
        })

        const programs = data?.myPrograms?.programs || []
        const duplicateProgram = programs.find(
          (program: { name: string; key: string }) =>
            program.name.toLowerCase() === name.trim().toLowerCase() &&
            (!isEdit || program.key !== currentProgramKey)
        )

Describe the solution you'd like
Handle uniqueness through backend validation only and introduce GraphQL error formatting so field-level validation errors (e.g., name) can be passed via extensions and mapped directly to the form. This will remove the extra request and keep validation centralized.

Are you going to work on implementing this?

  • Yes
  • No

Additional context
frontend/src/components/ProgramForm.tsx

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions