diff --git a/src/components/application/application_form.tsx b/src/components/application/application_form.tsx index dcf3d90d..926a2464 100644 --- a/src/components/application/application_form.tsx +++ b/src/components/application/application_form.tsx @@ -104,8 +104,8 @@ export default function ApplicationForm(props: ApplicationFormProperties) { const validateFormState = useCallback(() => { // console.log("validateFormState"); - if (formState.touchedFields.protectedAmount === undefined) { - console.log("amount not touched, not calculating premium..."); + if (getValues().protectedAmount === undefined || getValues().protectedAmount === "") { + console.log("amount empty, not calculating premium..."); return false; } @@ -372,11 +372,24 @@ export default function ApplicationForm(props: ApplicationFormProperties) { textField: { variant: INPUT_VARIANT, fullWidth: true, + error: errors.coverageEndDate !== undefined || field.value?.isBefore(coverageUntilMin, 'day') || field.value?.isAfter(coverageUntilMax, 'day'), + helperText: errors.coverageEndDate !== undefined + ? t('error.field.required', { ns: 'common' }) + : (field.value?.isBefore(coverageUntilMin, 'day') + ? t('error.field.min', { ns: 'common', minValue: coverageUntilMin.format('DD.MM.YYYY') }) + : (field.value?.isAfter(coverageUntilMax, 'day') + ? t('error.field.max', { ns: 'common', maxValue: coverageUntilMax.format('DD.MM.YYYY') }) + : "" + ) + ) } }} - onAccept={async (date) => { - setValue("coverageDuration", dayjs(date).startOf('day').diff(dayjs().startOf('day'), 'days').toString()); - await calculatePremium(); + onChange={async (date) => { + field.onChange(date); + if (date && date.isValid()) { + setValue("coverageDuration", dayjs(date).startOf('day').diff(dayjs().startOf('day'), 'days').toString(), { shouldValidate: true }); + await calculatePremium(); + } }} disablePast={true} minDate={coverageUntilMin} diff --git a/src/components/show_bundle/bundle_extend_form.tsx b/src/components/show_bundle/bundle_extend_form.tsx index d0d3fc78..8c730382 100644 --- a/src/components/show_bundle/bundle_extend_form.tsx +++ b/src/components/show_bundle/bundle_extend_form.tsx @@ -5,7 +5,7 @@ import { DatePicker } from "@mui/x-date-pickers"; import dayjs, { Dayjs } from "dayjs"; import { BigNumber } from "ethers"; import { useTranslation } from "next-i18next"; -import { useState } from "react"; +import { useMemo, useState } from "react"; import { Controller, SubmitHandler, useForm } from "react-hook-form"; import { BundleData } from "../../backend/bundle_data"; import { INPUT_VARIANT } from "../../config/theme"; @@ -44,7 +44,7 @@ export default function BundleExtendForm(props: BundleExtendFormProps) { } }); - // const errors = useMemo(() => formState.errors, [formState]); + const errors = useMemo(() => formState.errors, [formState]); const onSubmit: SubmitHandler = async data => { console.log("submit clicked", data); @@ -83,6 +83,16 @@ export default function BundleExtendForm(props: BundleExtendFormProps) { textField: { variant: INPUT_VARIANT, fullWidth: true, + error: errors.extensionEndDate !== undefined || field.value?.isBefore(minExtensionDate, 'day') || field.value?.isAfter(maxExtensionDate, 'day'), + helperText: errors.extensionEndDate !== undefined + ? t('error.field.required', { ns: 'common' }) + : (field.value?.isBefore(minExtensionDate, 'day') + ? t('error.field.min', { ns: 'common', minValue: minExtensionDate.format('DD.MM.YYYY') }) + : (field.value?.isAfter(maxExtensionDate, 'day') + ? t('error.field.max', { ns: 'common', maxValue: maxExtensionDate.format('DD.MM.YYYY') }) + : "" + ) + ) } }} disablePast={true} diff --git a/src/components/stake/staking_form.tsx b/src/components/stake/staking_form.tsx index 980e202b..d7dc56b6 100644 --- a/src/components/stake/staking_form.tsx +++ b/src/components/stake/staking_form.tsx @@ -234,6 +234,16 @@ export default function StakingForm(props: StakingFormProperties) { textField: { variant: INPUT_VARIANT, fullWidth: true, + error: errors.lifetimeEndDate !== undefined || field.value?.isBefore(minLifetimeEndDate, 'day') || field.value?.isAfter(maxLifetimeEndDate, 'day'), + helperText: errors.lifetimeEndDate !== undefined + ? t('error.field.required', { ns: 'common' }) + : (field.value?.isBefore(minLifetimeEndDate, 'day') + ? t('error.field.min', { ns: 'common', minValue: minLifetimeEndDate.format('DD.MM.YYYY') }) + : (field.value?.isAfter(maxLifetimeEndDate, 'day') + ? t('error.field.max', { ns: 'common', maxValue: maxLifetimeEndDate.format('DD.MM.YYYY') }) + : "" + ) + ) } }} disablePast={true} diff --git a/src/version.json b/src/version.json index f1925d3c..9a8f01ab 100644 --- a/src/version.json +++ b/src/version.json @@ -1 +1 @@ -{"name": "depeg-interface", "version": "1.2.7", "date": "2023-12-27" } +{"name": "depeg-interface", "version": "1.2.14", "date": "2026-07-11" }