Skip to content

Commit

Permalink
refactor: refactor formcontent
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Dec 4, 2024
1 parent c71fe90 commit f002dea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/components/merge/DefaultMergeFormContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import { StandardFormSectionTitle } from '../standardForm'
export const DefaultMergeFormContents = ({
children,
title,
}: React.PropsWithChildren<{ title?: React.ReactNode }>) => {
mergeCompleteElement = <MergeComplete />,
}: React.PropsWithChildren<{
title?: React.ReactNode
mergeCompleteElement?: React.ReactElement
}>) => {
const { submitting, submitSucceeded } = useFormState({
subscription: { submitting: true, submitSucceeded: true },
})

if (submitSucceeded) {
return <MergeComplete />
return mergeCompleteElement
}

if (submitting) {
Expand Down Expand Up @@ -58,12 +62,13 @@ export const MergeInProgress = () => {
)
}

export const MergeComplete = () => {
export const MergeComplete = ({ children }: React.PropsWithChildren) => {
return (
<div>
<StandardFormSectionTitle>
{i18n.t('Merge complete')}
</StandardFormSectionTitle>
{children}
<LinkButton to="../">{i18n.t('Back to list')}</LinkButton>
</div>
)
Expand Down
5 changes: 0 additions & 5 deletions src/components/merge/MergeFormBase.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import i18n from '@dhis2/d2-i18n'
import { Button, ButtonStrip, Card, CircularLoader } from '@dhis2/ui'
import React from 'react'
import { Form } from 'react-final-form'
import { DefaultFormErrorNotice } from '../form/DefaultFormErrorNotice'
import { LinkButton } from '../LinkButton'
import { LoadingSpinner } from '../loading/LoadingSpinner'
import { MergeFormValuesBase } from './mergeSchemaBase'

export type MergeFormBaseProps<TValues> = {
Expand Down
16 changes: 15 additions & 1 deletion src/pages/indicatorTypes/Merge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { useDataEngine } from '@dhis2/app-runtime'
import { FORM_ERROR } from 'final-form'
import React, { useMemo } from 'react'
import { StandardFormSectionTitle } from '../../components'
import { DefaultMergeFormContents, MergeFormBase } from '../../components/merge'
import {
DefaultMergeFormContents,
MergeComplete,
MergeFormBase,
} from '../../components/merge'
import { getDefaults, useLocationWithState } from '../../lib'
import { IndicatorTypeMergeForm } from './merge/IndicatorTypeMerge'
import {
Expand Down Expand Up @@ -56,6 +60,16 @@ export const Component = () => {
Configure indicator type merge
</StandardFormSectionTitle>
}
mergeCompleteElement={
<MergeComplete>
<p>
The indicator types merge operation is complete.
<br /> <br />
All selected indicator types were merged
successfully.
</p>
</MergeComplete>
}
>
<IndicatorTypeMergeForm />
</DefaultMergeFormContents>
Expand Down

0 comments on commit f002dea

Please sign in to comment.