Skip to content

Commit

Permalink
Merge forms in one page for create and another for edit and change pa…
Browse files Browse the repository at this point in the history
…ths in Router
  • Loading branch information
anagperal committed Jun 28, 2024
1 parent bb23eef commit efc8d44
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ type FormPageProps = {
};

export const FormPage: React.FC<FormPageProps> = React.memo(
({ title, subtitle = "", saveLabel = "", cancelLabel = "", children, onSave, onCancel }) => {
({ title, subtitle, saveLabel, cancelLabel, children, onSave, onCancel }) => {
return (
<StyledFormPage>
<Header>
<TitleContainer>
{title ? <Title>{title}</Title> : null}
{subtitle ? <Subtitle>{subtitle}</Subtitle> : null}
{title && <Title>{title}</Title>}
{subtitle && <Subtitle>{subtitle}</Subtitle>}
</TitleContainer>
<RequiredText>{i18n.t("Indicates required")}</RequiredText>
</Header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const FormSection: React.FC<FormSectionProps> = React.memo(
{hasSeparator && <Separator margin="12px" />}
<Container direction={direction}>
{title && (
<TitleContainer>
<TitleContainer direction={direction}>
<RequiredText className={required ? "required" : ""}>
{title}
</RequiredText>
Expand All @@ -37,7 +37,7 @@ export const FormSection: React.FC<FormSectionProps> = React.memo(
)}
</TitleContainer>
)}
<FormContainer>{children}</FormContainer>
<FormContainer fulWidth={!title}>{children}</FormContainer>
</Container>
</FormSectionContainer>
);
Expand All @@ -55,16 +55,21 @@ const Container = styled.div<{ direction: string }>`
width: 100%;
gap: ${props => (props.direction === "row" ? "48px" : "24px")};
align-items: ${props => (props.direction === "row" ? "center" : "flex-start")};
@media (max-width: 600px) {
flex-direction: column;
align-items: flex-start;
}
`;

const TitleContainer = styled.div`
const TitleContainer = styled.div<{ direction: string }>`
display: flex;
align-items: center;
gap: 4px;
width: 30%;
`;

const FormContainer = styled.div`
width: 100%;
const FormContainer = styled.div<{ fulWidth: boolean }>`
width: ${props => (props.fulWidth ? "100%" : "70%")};
`;

const RequiredText = styled.span`
Expand Down
2 changes: 1 addition & 1 deletion src/webapp/components/layout/side-bar/SideBarContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const SideBarContent: React.FC<SideBarContentProps> = React.memo(
const history = useHistory();

const goToCreateEvent = useCallback(() => {
history.push(`/create-event`);
history.push(`/create/diseaseOutbreakEvent`);
}, [history]);

return (
Expand Down
28 changes: 12 additions & 16 deletions src/webapp/pages/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,31 @@ import { EventTrackerPage } from "./event-tracker/EventTrackerPage";
import { IncidentActionPlanPage } from "./incident-action-plan/IncidentActionPlanPage";
import { ResourcesPage } from "./resources/ResourcesPage";
import { IMTeamBuilderPage } from "./incident-management-team-builder/IMTeamBuilderPage";
import { CreateEventPage } from "./create-event/CreateEventPage";
import { CreateRiskAssessmentPage } from "./create-risk-assessment/CreateRiskAssessmentPage";
import { CreateIncidentActionPlanPage } from "./create-incident-action-plan/CreateIncidentActionPlanPage";
import { AssignRolePage } from "./assign-role/AssignRolePage";
import { EditFormPage } from "./edit-form/EditFormPage";
import { CreateFormPage } from "./create-form/CreateFormPage";

export function Router() {
return (
<HashRouter>
<Switch>
<Route path="/create-event" render={() => <CreateEventPage />} />
<Route path="/event-tracker/:event" render={() => <EventTrackerPage />} />
<Route path="/create/:formType" render={() => <CreateFormPage />} />
<Route
path="/create-risk-assessment/:event"
render={() => <CreateRiskAssessmentPage />}
path="/edit/:formType/:diseaseOutbreakEventId/:id?"
render={() => <EditFormPage />}
/>
<Route
path="/incident-management-team-builder/:event"
render={() => <IMTeamBuilderPage />}
path="/event-tracker/:diseaseOutbreakEvent"
render={() => <EventTrackerPage />}
/>
<Route path="/assign-role/:event" render={() => <AssignRolePage />} />
<Route
path="/incident-action-plan/:event"
render={() => <IncidentActionPlanPage />}
path="/incident-management-team-builder/:diseaseOutbreakEvent"
render={() => <IMTeamBuilderPage />}
/>
<Route
path="/create-incident-action-plan/:event"
render={() => <CreateIncidentActionPlanPage />}
path="/:diseaseOutbreakEvent/incident-action-plan/:incidentActionPlan"
render={() => <IncidentActionPlanPage />}
/>
<Route path="/resources/:event" render={() => <ResourcesPage />} />
<Route path="/resources/:diseaseOutbreakEvent" render={() => <ResourcesPage />} />
{/* Default route */}
<Route render={() => <DashboardPage />} />
</Switch>
Expand Down
16 changes: 0 additions & 16 deletions src/webapp/pages/assign-role/AssignRolePage.tsx

This file was deleted.

8 changes: 0 additions & 8 deletions src/webapp/pages/create-event/CreateEventPage.tsx

This file was deleted.

14 changes: 14 additions & 0 deletions src/webapp/pages/create-form/CreateFormPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";

import { Layout } from "../../components/layout/Layout";
import { FormPage } from "../../components/form/FormPage";

export const CreateFormPage: React.FC = React.memo(() => {
return (
<Layout title="Form Title" subtitle="Form Subtitle" hideSideBarOptions>
<FormPage title="title" subtitle="subtitle" onSave={() => {}}>
<div>CreateFormPage</div>
</FormPage>
</Layout>
);
});

This file was deleted.

This file was deleted.

14 changes: 14 additions & 0 deletions src/webapp/pages/edit-form/EditFormPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";

import { Layout } from "../../components/layout/Layout";
import { FormPage } from "../../components/form/FormPage";

export const EditFormPage: React.FC = React.memo(() => {
return (
<Layout title="Form Title" subtitle="Form Subtitle" hideSideBarOptions>
<FormPage title="title" subtitle="subtitle" onSave={() => {}}>
<div>EditFormPage</div>
</FormPage>
</Layout>
);
});

0 comments on commit efc8d44

Please sign in to comment.