Skip to content

Commit

Permalink
Added form onsave method handler
Browse files Browse the repository at this point in the history
  • Loading branch information
maikofelix47 committed Jul 8, 2023
1 parent 391bffe commit 1e6d743
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
12 changes: 10 additions & 2 deletions apps/front-end/src/app/components/encounters/encounter-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,25 @@ const EncounterForm: React.FC = ()=>{
encounterTypeUuid: string;
uuid: string;
visitUuid: string;
encounterUuid: string;
};
const [form,setForm] = useState<FormSchema>();

useEffect(()=>{
const f = getFormByEncounterType(data.encounterTypeUuid);
setForm(f);
},[data.encounterTypeUuid]);

const handleSaveForm = (formData: any)=>{
const payload = {
...formData,
encounterUuid: data.encounterUuid
};
return;
};
return(
<div>
{ form ?
<FormRenderer formSchema={form} /> : ''
<FormRenderer formSchema={form} onSave={handleSaveForm}/> : ''
}
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const EncounterList: React.FC<{
return;
};

const onClickEditHandler = (encounterTypeUuid: string,visitUuid: string)=>{
navigate(`./${visitUuid}/encounter-form/${encounterTypeUuid}`)
const onClickEditHandler = (visitUuid: string,encounterTypeUuid: string,encounterUuid: string)=>{
navigate(`./${visitUuid}/encounter/${encounterUuid}/encounter-form/${encounterTypeUuid}`)

};

Expand All @@ -64,7 +64,7 @@ const EncounterList: React.FC<{
</Button>
<Button
type="default"
onClick={() => onClickEditHandler(e.encounterType?.uuid,e.visit?.uuid)}
onClick={() => onClickEditHandler(e.visit.uuid,e.encounterType?.uuid,e.uuid)}
>
<EditOutlined />
</Button>
Expand Down
10 changes: 7 additions & 3 deletions apps/front-end/src/app/forms/form-renderer/form-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import { Input, Button } from 'antd';
import { FormSchema } from '../types';

interface FormRendererProps{
formSchema: FormSchema
formSchema: FormSchema;
onSave:(data: any)=>any;
}

const FormRenderer: React.FC<FormRendererProps> = ({formSchema}) => {
const FormRenderer: React.FC<FormRendererProps> = ({formSchema,onSave}) => {
const {
handleSubmit,
control,
formState: { errors },
} = useForm();
const onSubmit: SubmitHandler<any> = (data) => console.log(data);
const onSubmit: SubmitHandler<any> = (data) => {
console.log(data);
onSave(data);
};

return (<form onSubmit={handleSubmit(onSubmit)}>
<h2>{formSchema.name}</h2>
Expand Down
2 changes: 1 addition & 1 deletion apps/front-end/src/app/routes/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const appRouter = createBrowserRouter([
},
},
{
path: ':uuid/visits/:visitUuid/encounter-form/:encounterTypeUuid',
path: ':uuid/visits/:visitUuid/encounter/:encounterUuid/encounter-form/:encounterTypeUuid',
element: <EncounterForm />,
loader: ({ params }) => {
return params;
Expand Down

0 comments on commit 1e6d743

Please sign in to comment.