Skip to content

Commit

Permalink
Disbale form submit after already submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
HRemonen committed Mar 3, 2023
1 parent 4ffd0e2 commit 7c98b01
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/client/components/InteractiveForm/RenderSurvey.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { useState } from 'react'
import { Box, Button } from '@mui/material'
import { useTranslation } from 'react-i18next'

import { InputProps } from '../../types'
import SelectFaculty from './SelectFaculty'
import RenderQuestions from './RenderQuestions'
Expand All @@ -15,6 +14,7 @@ const RenderSurvey = ({
}: InputProps) => {
const { t, i18n } = useTranslation()
const classes = styles.cardStyles
const [disableForm, setDisableForm] = useState(false)
const [showQuestions, setShowQuestions] = useState(false)

if (!questions) return null
Expand All @@ -37,6 +37,11 @@ const RenderSurvey = ({
return isFacultySelected && isAnyDimensionsSelected
}

const submitFormData = (data: any) => {
setDisableForm(true)
handleSubmit(data)
}

return (
<Box sx={{ mx: 2, maxWidth: 1080, border: 1, borderColor: 'grey.300' }}>
<SelectFaculty control={control} />
Expand Down Expand Up @@ -77,7 +82,11 @@ const RenderSurvey = ({
{t('openForm')}
</Button>
) : (
<Button data-cy="submit-form-button" onClick={handleSubmit}>
<Button
data-cy="submit-form-button"
disabled={disableForm}
onClick={submitFormData}
>
{t('submit')}
</Button>
)}
Expand Down

0 comments on commit 7c98b01

Please sign in to comment.