Skip to content

Commit

Permalink
Merge pull request #148 from onehealthtoolkit/fix_issues
Browse files Browse the repository at this point in the history
Request to delete account screen
  • Loading branch information
pphetra authored Dec 21, 2023
2 parents a0bcac6 + 6c37421 commit 6bac6fe
Show file tree
Hide file tree
Showing 36 changed files with 1,083 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},

"prettier.eslintIntegration": true,
Expand Down
11 changes: 9 additions & 2 deletions components/admin/formBuilder/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ import { ConfirmDialog } from "components/admin/formBuilder/shared";

export type FormBuilderProps = {
viewModel: FormViewModel;
rendererDataTemplate: string;
};

const FormBuilder: FC<FormBuilderProps> = ({ viewModel: form }) => {
const FormBuilder: FC<FormBuilderProps> = ({
viewModel: form,
rendererDataTemplate,
}) => {
const elementRef = useRef<HTMLDivElement>(null);

const { t } = useTranslation();
Expand Down Expand Up @@ -149,7 +153,10 @@ const FormBuilder: FC<FormBuilderProps> = ({ viewModel: form }) => {
</div>
) : (
form.formSimulation && (
<FormSimulation viewModel={form.formSimulation} />
<FormSimulation
viewModel={form.formSimulation}
rendererDataTemplate={rendererDataTemplate}
/>
)
)}

Expand Down
12 changes: 10 additions & 2 deletions components/admin/formBuilder/formViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FormSimulationViewModel } from "components/admin/formBuilder/simulator/
import { action, computed, makeObservable, observable } from "mobx";
import { v4 as uuidv4 } from "uuid";
import { SubformFieldViewModel } from "./field";
import { IReportTypeService } from "lib/services/reportType/reportTypeService";

export type FormVariableItem = { label: string; value: string; type: string };

Expand All @@ -26,7 +27,9 @@ export class FormViewModel extends MovableItemsViewModel<SectionViewModel> {
public builtinVariables: FormVariableItem[] = [],
id?: string,
label?: string,
readonly parent?: FormViewModel
readonly parent?: FormViewModel,
readonly reportTypeService?: IReportTypeService,
readonly reportTypeId?: string
) {
super(id || "", label || "");
makeObservable(this, {
Expand Down Expand Up @@ -241,7 +244,12 @@ export class FormViewModel extends MovableItemsViewModel<SectionViewModel> {
set isSimulationMode(isSimulationMode: boolean) {
this._isSimulationMode = isSimulationMode;
if (isSimulationMode) {
this.formSimulation = new FormSimulationViewModel(this.jsonString);
this.formSimulation = new FormSimulationViewModel(
this.jsonString,
undefined,
this.reportTypeService,
this.reportTypeId
);
}
}

Expand Down
34 changes: 31 additions & 3 deletions components/admin/formBuilder/simulator/formSimulation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@ import tw from "tailwind-styled-components";

type FormSimulationProps = {
viewModel?: FormSimulationViewModel;
rendererDataTemplate: string;
onSubmit?: () => void;
};

const FormSimulation = ({ viewModel: form, onSubmit }: FormSimulationProps) => {
const FormSimulation = ({
viewModel: form,
onSubmit,
rendererDataTemplate,
}: FormSimulationProps) => {
if (!form) {
return null;
}

if (rendererDataTemplate) form.rendererDataTemplate = rendererDataTemplate;

return !form.errorRendering ? (
<div className={`flex flex-col relative w-full`}>
<Stepper viewModel={form} />
Expand All @@ -25,8 +32,28 @@ const FormSimulation = ({ viewModel: form, onSubmit }: FormSimulationProps) => {

<FormInput viewModel={form} />
{form.isSubmitted && (
<div className="rounded p-4 border-2 border-green-300 text-green-600">
Simulating submission is complete.
<div className="rounded p-4 border-2 border-green-30">
<div className="text-green-600 text-2xl">
Simulating submission is complete
</div>
<div className="text-green-700">Case Definitions: </div>
<ul className="text-gray-600 pl-10 list-disc">
{form.simulatorIncidentReportType?.caseDefinitions.map(item => (
<li key={item.id}>{item.description}</li>
))}
</ul>
<div className="text-green-700">Reporter Alerts:</div>
<ul className="text-gray-600 pl-10 list-disc">
{form.simulatorIncidentReportType?.reporterNotifications.map(
item => (
<li key={item.id}>{item.name}</li>
)
)}
</ul>
<div className="text-green-700">Description:</div>
<ul className="text-gray-600 pl-10">
<li>{form.simulatorIncidentReportType?.rendererData}</li>
</ul>
</div>
)}
<Footer viewModel={form} onSubmit={onSubmit} />
Expand Down Expand Up @@ -114,6 +141,7 @@ const Footer = ({
onClick={(e: MouseEvent) => {
e.preventDefault();
form.next();
console.log("isSubmitting", form.form?.toJsonValue());
if (form.isSubmitting && onSubmit) {
onSubmit();
}
Expand Down
26 changes: 24 additions & 2 deletions components/admin/formBuilder/simulator/formSimulationViewModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Form from "lib/opsvForm/models/form";
import { parseForm } from "lib/opsvForm/models/json";
import Section from "lib/opsvForm/models/section";
import { IReportTypeService } from "lib/services/reportType";
import { SimulationReportType } from "lib/services/reportType/reportType";
import {
action,
computed,
Expand All @@ -15,19 +17,29 @@ export class FormSimulationViewModel {
errorRendering = false;
isSubmitting = false;
isSubmitted = false;
rendererDataTemplate?: string;
simulatorIncidentReportType?: SimulationReportType = undefined;

constructor(readonly definition: string, readonly formRef?: string) {
constructor(
readonly definition: string,
readonly formRef?: string,
readonly reportTypeService?: IReportTypeService,
readonly reportTypeId?: string,
rendererDataTemplate?: string
) {
makeObservable(this, {
form: observable,
errorRendering: observable,
isSubmitting: observable,
isSubmitted: observable,
simulatorIncidentReportType: observable,
currentSection: computed,
next: action,
previous: action,
isFirst: computed,
isLast: computed,
});
this.rendererDataTemplate = rendererDataTemplate;
this._init();
}

Expand Down Expand Up @@ -81,9 +93,19 @@ export class FormSimulationViewModel {
this.form?.previous();
}

submit() {
async submit() {
this.isSubmitting = true;
this.isSubmitted = false;
if (this.reportTypeService) {
this.simulatorIncidentReportType =
await this.reportTypeService.submitSimulationReport(
this.form?.toJsonValue(),
new Date().toISOString().split("T")[0],
this.rendererDataTemplate || "",
undefined,
this.reportTypeId
);
}
setTimeout(() => {
runInAction(() => {
this.isSubmitting = false;
Expand Down
5 changes: 4 additions & 1 deletion components/admin/observationDefinition/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ const ObservationDefinitionCreate = () => {
viewModel.definitionFormViewModel.jsonString;
}}
>
<FormBuilder viewModel={viewModel.definitionFormViewModel} />
<FormBuilder
viewModel={viewModel.definitionFormViewModel}
rendererDataTemplate={viewModel.descriptionTemplate}
/>
</FormBuilderDialog>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ const ObservationMonitoringDefinitionCreate = () => {
viewModel.definitionFormViewModel.jsonString;
}}
>
<FormBuilder viewModel={viewModel.definitionFormViewModel} />
<FormBuilder
viewModel={viewModel.definitionFormViewModel}
rendererDataTemplate={viewModel.descriptionTemplate}
/>
</FormBuilderDialog>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ const ObservationMonitoringDefinitionsUpdateForm = () => {
viewModel.definitionFormViewModel.jsonString;
}}
>
<FormBuilder viewModel={viewModel.definitionFormViewModel} />
<FormBuilder
viewModel={viewModel.definitionFormViewModel}
rendererDataTemplate={viewModel.descriptionTemplate}
/>
</FormBuilderDialog>
</>
</MaskingLoader>
Expand Down
5 changes: 4 additions & 1 deletion components/admin/observationDefinition/update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,10 @@ const ObservationDefinitionsUpdateForm = () => {
viewModel.definitionFormViewModel.jsonString;
}}
>
<FormBuilder viewModel={viewModel.definitionFormViewModel} />
<FormBuilder
viewModel={viewModel.definitionFormViewModel}
rendererDataTemplate={viewModel.descriptionTemplate}
/>
</FormBuilderDialog>
</>
);
Expand Down
10 changes: 8 additions & 2 deletions components/admin/reportType/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,10 @@ const ReportTypeCreate = () => {
viewModel.definition = viewModel.definitionFormViewModel.jsonString;
}}
>
<FormBuilder viewModel={viewModel.definitionFormViewModel} />
<FormBuilder
viewModel={viewModel.definitionFormViewModel}
rendererDataTemplate={viewModel.rendererDataTemplate}
/>
</FormBuilderDialog>
<FormBuilderDialog
viewModel={viewModel.dialog("followupDefinitionFormBuilder")}
Expand All @@ -333,7 +336,10 @@ const ReportTypeCreate = () => {
viewModel.followupDefinitionFormViewModel.jsonString;
}}
>
<FormBuilder viewModel={viewModel.followupDefinitionFormViewModel} />
<FormBuilder
viewModel={viewModel.followupDefinitionFormViewModel}
rendererDataTemplate={viewModel.rendererFollowupDataTemplate}
/>
</FormBuilderDialog>
</>
);
Expand Down
7 changes: 5 additions & 2 deletions components/admin/reportType/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const ReportTypeList = () => {
<TableIcon
className="w-5 h-5 text-gray-600 hover:text-gray-900 cursor-pointer"
onClick={() => {
viewModel.openFormSimulationDialog(record.definition);
viewModel.openFormSimulationDialog(record);
}}
/>
</Tooltip>
Expand Down Expand Up @@ -263,7 +263,10 @@ const ReportTypeList = () => {
/>

<FormSimulationDialog viewModel={viewModel.dialog("formSimulation")}>
<FormSimulation viewModel={viewModel.formSimulationViewModel} />
<FormSimulation
viewModel={viewModel.formSimulationViewModel}
rendererDataTemplate=""
/>
</FormSimulationDialog>

<QrcodeDialog
Expand Down
10 changes: 8 additions & 2 deletions components/admin/reportType/listViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,14 @@ export class AdminReportTypeListViewModel extends BaseViewModel {
);
}

openFormSimulationDialog(definition: string) {
this.formSimulationViewModel = new FormSimulationViewModel(definition);
openFormSimulationDialog(item: ReportType) {
this.formSimulationViewModel = new FormSimulationViewModel(
item.definition,
undefined,
this.reportTypeService,
item.id,
item.rendererDataTemplate
);
this.dialog("formSimulation")?.open(null);
}

Expand Down
Loading

0 comments on commit 6bac6fe

Please sign in to comment.