fix: reset mod form when route changes from edit to submit
All checks were successful
Release to Staging / build_and_release (push) Successful in 45s

This commit is contained in:
daniyal 2024-08-26 18:44:00 +05:00
parent dc19e614df
commit 1927887992

View File

@ -25,8 +25,8 @@ import {
} from '../utils'
import { CheckboxField, InputError, InputField } from './Inputs'
import { RelayController } from '../controllers'
import { useNavigate } from 'react-router-dom'
import { getModsInnerPageRoute } from '../routes'
import { useLocation, useNavigate } from 'react-router-dom'
import { appRoutes, getModsInnerPageRoute } from '../routes'
import { DownloadUrl, ModFormState, ModDetails } from '../types'
import { LoadingSpinner } from './LoadingSpinner'
import { T_TAG_VALUE } from '../constants'
@ -55,6 +55,7 @@ type ModFormProps = {
}
export const ModForm = ({ existingModData }: ModFormProps) => {
const location = useLocation()
const navigate = useNavigate()
const userState = useAppSelector((state) => state.user)
@ -64,6 +65,12 @@ export const ModForm = ({ existingModData }: ModFormProps) => {
initializeFormState(existingModData)
)
useEffect(() => {
if (location.pathname === appRoutes.submitMod) {
setFormState(initializeFormState())
}
}, [location.pathname]) // Only trigger when the pathname changes to submit-mod
const [formErrors, setFormErrors] = useState<FormErrors>({})
useEffect(() => {