Skip to content

Commit

Permalink
Merge pull request #1233 from Chia-Network/refactor/fix/asterisks-on-…
Browse files Browse the repository at this point in the history
…required-fields

Refactor/fix/asterisks on required fields : issue #1222
  • Loading branch information
wwills2 authored May 10, 2024
2 parents 50c69d8 + c44167a commit 81c8819
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 207 deletions.
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

0 comments on commit 81c8819

Please sign in to comment.