generated from EyeSeeTea/dhis2-app-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create disease outbreak event form in presentation layer
- Loading branch information
Showing
23 changed files
with
1,840 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { FutureData } from "../../data/api-futures"; | ||
import { DiseaseOutbreakEvent } from "../entities/DiseaseOutbreakEvent"; | ||
import { Future } from "../entities/generic/Future"; | ||
|
||
export class GetDiseaseOutbreakEventUseCase { | ||
public execute(id: string): FutureData<DiseaseOutbreakEvent> { | ||
return Future.success({} as DiseaseOutbreakEvent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
import i18n from "../../../utils/i18n"; | ||
import { TextInput } from "../text-input/TextInput"; | ||
import { MemberSelector } from "../member-selector/MemberSelector"; | ||
import { FormField, FormFieldState } from "./FormFieldState"; | ||
import { useDebounce } from "../../hooks/useDebounce"; | ||
import { MultipleSelector } from "../selector/MultipleSelector"; | ||
import { Selector } from "../selector/Selector"; | ||
import { RadioButtonsGroup } from "../radio-buttons-group/RadioButtonsGroup"; | ||
import { TextArea } from "../text-input/TextArea"; | ||
import { DatePicker } from "../date-picker/DatePicker"; | ||
import { Checkbox } from "../checkbox/Checkbox"; | ||
|
||
export type FieldWidgetProps = { | ||
onChange: (updatedField: FormFieldState) => void; | ||
field: FormFieldState; | ||
disabled?: boolean; | ||
}; | ||
|
||
export const FieldWidget: React.FC<FieldWidgetProps> = React.memo(props => { | ||
const { field, onChange, disabled = false } = props; | ||
const [textFieldValue, setTextFieldValue] = useState<string>( | ||
field.type === "text" ? field.value : "" | ||
); | ||
const debouncedTextFieldValue = useDebounce(textFieldValue); | ||
|
||
useEffect(() => { | ||
if (debouncedTextFieldValue !== field.value && field.type === "text") { | ||
onChange(FormField.updateState(field, debouncedTextFieldValue)); | ||
} | ||
}, [debouncedTextFieldValue, field, onChange]); | ||
|
||
switch (field.type) { | ||
case "select": { | ||
return field.multiple && field.options && Array.isArray(field.value) ? ( | ||
<MultipleSelector | ||
id={field.id} | ||
placeholder={field.placeholder} | ||
label={field.label} | ||
selected={field.value} | ||
onChange={newValue => onChange(FormField.updateState(field, newValue))} | ||
options={field.options} | ||
helperText={field.helperText} | ||
errorText={field.errors ? field.errors.join("/n") : ""} | ||
error={field.errors && field.errors.length > 0} | ||
required={field.required && field.showIsRequired} | ||
disabled={disabled} | ||
/> | ||
) : !field.multiple && field.options && typeof field.value === "string" ? ( | ||
<Selector | ||
id={field.id} | ||
placeholder={field.placeholder} | ||
label={field.label} | ||
selected={field.value} | ||
onChange={newValue => onChange(FormField.updateState(field, newValue))} | ||
options={field.options} | ||
helperText={field.helperText} | ||
errorText={field.errors ? field.errors.join("/n") : ""} | ||
error={field.errors && field.errors.length > 0} | ||
required={field.required && field.showIsRequired} | ||
disabled={disabled} | ||
/> | ||
) : ( | ||
<span>{i18n.t("Error displaying this field in the form")}</span> | ||
); | ||
} | ||
|
||
case "radio": { | ||
return field.options && typeof field.value === "string" ? ( | ||
<RadioButtonsGroup | ||
id={field.id} | ||
label={field.label} | ||
selected={field.value} | ||
onChange={event => onChange(FormField.updateState(field, event.target.value))} | ||
options={field.options} | ||
helperText={field.helperText} | ||
errorText={field.errors ? field.errors.join("/n") : ""} | ||
error={field.errors && field.errors.length > 0} | ||
required={field.required && field.showIsRequired} | ||
disabled={disabled} | ||
/> | ||
) : ( | ||
<span>{i18n.t("Error displaying this field in the form")}</span> | ||
); | ||
} | ||
|
||
case "text": | ||
return field.multiline ? ( | ||
<TextArea | ||
id={field.id} | ||
label={field.label} | ||
value={textFieldValue} | ||
onChange={newValue => setTextFieldValue(newValue)} | ||
helperText={field.helperText} | ||
errorText={field.errors ? field.errors.join("/n") : ""} | ||
error={field.errors && field.errors.length > 0} | ||
required={field.required && field.showIsRequired} | ||
disabled={disabled} | ||
/> | ||
) : ( | ||
<TextInput | ||
id={field.id} | ||
label={field.label} | ||
value={textFieldValue} | ||
onChange={event => setTextFieldValue(event.target.value)} | ||
helperText={field.helperText} | ||
errorText={field.errors ? field.errors.join("/n") : ""} | ||
error={field.errors && field.errors.length > 0} | ||
required={field.required && field.showIsRequired} | ||
disabled={disabled} | ||
/> | ||
); | ||
|
||
case "date": | ||
return ( | ||
<DatePicker | ||
id={field.id} | ||
label={field.label} | ||
value={field.value} | ||
onChange={newValue => onChange(FormField.updateState(field, newValue))} | ||
helperText={field.helperText} | ||
errorText={field.errors ? field.errors.join("/n") : ""} | ||
error={field.errors && field.errors.length > 0} | ||
required={field.required && field.showIsRequired} | ||
disabled={disabled} | ||
/> | ||
); | ||
|
||
case "boolean": { | ||
return ( | ||
<Checkbox | ||
id={field.id} | ||
label={field.label} | ||
checked={field.value} | ||
onChange={newValue => onChange(FormField.updateState(field, newValue))} | ||
helperText={field.helperText} | ||
disabled={disabled} | ||
/> | ||
); | ||
} | ||
|
||
case "member": { | ||
return ( | ||
<MemberSelector | ||
id={field.id} | ||
placeholder={field.placeholder} | ||
label={field.label} | ||
selected={field.value} | ||
onChange={newValue => onChange(FormField.updateState(field, newValue))} | ||
options={field.options} | ||
helperText={field.helperText} | ||
errorText={field.errors ? field.errors.join("/n") : ""} | ||
error={field.errors && field.errors.length > 0} | ||
required={field.required && field.showIsRequired} | ||
disabled={disabled} | ||
/> | ||
); | ||
} | ||
|
||
default: | ||
return <span>{i18n.t("Error displaying this field in the form")}</span>; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React from "react"; | ||
|
||
import { useForm } from "./useForm"; | ||
import { FormState } from "./FormState"; | ||
import { FormLayout } from "./FormLayout"; | ||
import { FormSection } from "./FormSection"; | ||
import { FormFieldState } from "./FormFieldState"; | ||
import { Layout } from "../layout/Layout"; | ||
|
||
export type FormProps = { | ||
formState: FormState; | ||
onFormChange: (newFormState: FormState, updatedField: FormFieldState) => void; | ||
onSave: () => void; | ||
onCancel?: () => void; | ||
}; | ||
|
||
export const Form: React.FC<FormProps> = React.memo(props => { | ||
const { formState, onFormChange, onSave, onCancel } = props; | ||
|
||
const { formLocalState, handleUpdateFormField } = useForm(formState, onFormChange); | ||
|
||
return ( | ||
<Layout title={formLocalState.title} subtitle={formLocalState.subtitle} hideSideBarOptions> | ||
<FormLayout | ||
title={formLocalState.titleDescripton} | ||
subtitle={formLocalState.subtitleDescripton} | ||
onSave={onSave} | ||
onCancel={onCancel} | ||
saveLabel={formLocalState.saveButtonLabel} | ||
disableSave={!formLocalState.isValid} | ||
> | ||
{formLocalState.sections.map(section => { | ||
if (!section.isVisible) return null; | ||
|
||
return ( | ||
<FormSection | ||
key={section.id} | ||
title={section.title} | ||
hasSeparator | ||
required={section.required} | ||
direction={section.direction} | ||
subsections={section.subsections} | ||
fields={section.fields} | ||
onUpdateField={handleUpdateFormField} | ||
/> | ||
); | ||
})} | ||
</FormLayout> | ||
</Layout> | ||
); | ||
}); |
Oops, something went wrong.