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

Refactor/fix/asterisks on required fields : issue #1222 #1233

Merged
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
14 changes: 10 additions & 4 deletions src/renderer/components/blocks/forms/CoBenifetsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { useRef, forwardRef, useImperativeHandle } from 'react';
import { Formik, Form, FormikProps } from 'formik';
import { forwardRef, useImperativeHandle, useRef } from 'react';
import { Form, Formik, FormikProps } from 'formik';
import { Field, Repeater } from '@/components';
import * as yup from 'yup';
import { CoBenefit } from '@/schemas/CoBenefit.schema';
import { PickList } from '@/schemas/PickList.schema';
import { validateAndSubmitFieldArrayForm, deepOmit } from '@/utils/formik-utils';
import { deepOmit, validateAndSubmitFieldArrayForm } from '@/utils/formik-utils';

const validationSchema = yup.object({
cobenefits: yup.array().of(
Expand All @@ -29,7 +29,12 @@ const CoBenefitsForm = forwardRef<CoBenefitsFormRef, CoBenefitsFormProps>(
const formikRef = useRef<FormikProps<any>>(null);

useImperativeHandle(ref, () => ({
submitForm: async () => deepOmit(await validateAndSubmitFieldArrayForm(formikRef, 'coBenefits'), ['orgUid', 'warehouseProjectId', 'timeStaged']),
submitForm: async () =>
deepOmit(await validateAndSubmitFieldArrayForm(formikRef, 'coBenefits'), [
'orgUid',
'warehouseProjectId',
'timeStaged',
]),
}));

return (
Expand Down Expand Up @@ -58,6 +63,7 @@ const CoBenefitsForm = forwardRef<CoBenefitsFormRef, CoBenefitsFormProps>(
freeform={true}
options={picklistOptions?.coBenefits}
readonly={readonly}
required={true}
initialValue={coBenefit.cobenefit}
/>
</div>
Expand Down
17 changes: 12 additions & 5 deletions src/renderer/components/blocks/forms/EstimationsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Form, Formik, FormikProps } from 'formik';
import { Field, Repeater } from '@/components';
import { Estimation } from '@/schemas/Estimation.schema';
import * as yup from 'yup';
import { validateAndSubmitFieldArrayForm, deepOmit } from '@/utils/formik-utils';
import { deepOmit, validateAndSubmitFieldArrayForm } from '@/utils/formik-utils';

const validationSchema = yup.object({
estimations: yup.array().of(
Expand All @@ -27,12 +27,16 @@ export interface EstimationsFormRef {
submitForm: () => Promise<any>;
}

const EstimationsForm = forwardRef<EstimationsFormRef, EstimationsFormProps>(
({ readonly = false, data, }, ref) => {
const formikRef = useRef<FormikProps<any>>(null);
const EstimationsForm = forwardRef<EstimationsFormRef, EstimationsFormProps>(({ readonly = false, data }, ref) => {
const formikRef = useRef<FormikProps<any>>(null);

useImperativeHandle(ref, () => ({
submitForm: async () => deepOmit(await validateAndSubmitFieldArrayForm(formikRef, 'estimations'), ['orgUid', 'warehouseProjectId', 'timeStaged']),
submitForm: async () =>
deepOmit(await validateAndSubmitFieldArrayForm(formikRef, 'estimations'), [
'orgUid',
'warehouseProjectId',
'timeStaged',
]),
}));

return (
Expand Down Expand Up @@ -64,20 +68,23 @@ const EstimationsForm = forwardRef<EstimationsFormRef, EstimationsFormProps>(
label="Crediting Period Start"
type="date"
readonly={readonly}
required={true}
initialValue={estimation.creditingPeriodStart}
/>
<Field
name={`${name}[${index}].creditingPeriodEnd`}
label="Crediting Period End"
type="date"
readonly={readonly}
required={true}
initialValue={estimation.creditingPeriodEnd}
/>
<Field
name={`${name}[${index}].unitCount`}
label="Unit Count"
type="number"
readonly={readonly}
required={true}
initialValue={estimation.unitCount}
/>
</div>
Expand Down
16 changes: 13 additions & 3 deletions src/renderer/components/blocks/forms/IssuancesForm.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { forwardRef, useRef, useImperativeHandle } from 'react';
import { forwardRef, useImperativeHandle, useRef } from 'react';
import { Form, Formik, FormikProps } from 'formik';
import * as yup from 'yup';
import { Field, Repeater, UnitSummary } from '@/components';
import { Issuance } from '@/schemas/Issuance.schema';
import { PickList } from '@/schemas/PickList.schema';
import { validateAndSubmitFieldArrayForm, deepOmit } from '@/utils/formik-utils';
import { deepOmit, validateAndSubmitFieldArrayForm } from '@/utils/formik-utils';

const validationSchema = yup.object({
issuances: yup.array().of(
Expand Down Expand Up @@ -39,7 +39,12 @@ const IssuancesForm = forwardRef<IssuancesFormRef, IssuancesFormProps>(
const formikRef = useRef<FormikProps<any>>(null);

useImperativeHandle(ref, () => ({
submitForm: async () => deepOmit(await validateAndSubmitFieldArrayForm(formikRef, 'issuances'), ['orgUid', 'warehouseProjectId', 'timeStaged']),
submitForm: async () =>
deepOmit(await validateAndSubmitFieldArrayForm(formikRef, 'issuances'), [
'orgUid',
'warehouseProjectId',
'timeStaged',
]),
}));

return (
Expand Down Expand Up @@ -73,20 +78,23 @@ const IssuancesForm = forwardRef<IssuancesFormRef, IssuancesFormProps>(
label="Start Date"
type="date"
readonly={readonly}
required={true}
initialValue={issuance.startDate}
/>
<Field
name={`${name}[${index}].endDate`}
label="End Date"
type="date"
readonly={readonly}
required={true}
initialValue={issuance.endDate}
/>
<Field
name={`${name}[${index}].verificationApproach`}
label="Verification Approach"
type="text"
readonly={readonly}
required={true}
initialValue={issuance.verificationApproach}
/>
<Field
Expand All @@ -96,13 +104,15 @@ const IssuancesForm = forwardRef<IssuancesFormRef, IssuancesFormProps>(
freeform={true}
options={picklistOptions?.verificationBody}
readonly={readonly}
required={true}
initialValue={issuance.verificationBody || ''}
/>
<Field
name={`${name}[${index}].verificationReportDate`}
label="Verification Report Date"
type="date"
readonly={readonly}
required={true}
initialValue={issuance.verificationReportDate || null}
/>
</div>
Expand Down
Loading
Loading