diff --git a/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardEditButton.tsx b/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardEditButton.tsx index 1ad783b07..80ffd4042 100644 --- a/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardEditButton.tsx +++ b/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardEditButton.tsx @@ -1,6 +1,14 @@ import { Button } from "@dhis2/ui"; import i18n from "@dhis2/d2-i18n"; +import { useNavigate, useParams } from "react-router-dom"; export function ScorecardEditButton() { - return ; + const { id } = useParams(); + const navigate = useNavigate(); + + const onEditClick = () => { + navigate(`/edit/${id}`); + }; + + return ; } diff --git a/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardOptionsControlButton.tsx b/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardOptionsControlButton.tsx index ba0bfb3cb..28da361bf 100644 --- a/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardOptionsControlButton.tsx +++ b/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardOptionsControlButton.tsx @@ -1,10 +1,19 @@ import i18n from "@dhis2/d2-i18n"; import { Button } from "@dhis2/ui"; +import { useBoolean } from "usehooks-ts"; +import { ScorecardOptionsModal } from "./ScorecardOptionsModal"; export function ScorecardOptionsControlButton() { + const { + value: hide, + setTrue: onClose, + setFalse: onShow, + } = useBoolean(true); + return ( <> - + {!hide && } + ); } diff --git a/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardOptionsModal.tsx b/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardOptionsModal.tsx new file mode 100644 index 000000000..d42e5a9fd --- /dev/null +++ b/packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardActions/components/ScorecardOptionsModal.tsx @@ -0,0 +1,153 @@ +import i18n from "@dhis2/d2-i18n"; +import { + Button, + ButtonStrip, + Field, + Modal, + ModalActions, + ModalContent, + ModalTitle, + Radio, +} from "@dhis2/ui"; +import { AverageDisplayType } from "@scorecard/shared"; +import React from "react"; +import { useScorecardState } from "../../../state/state"; +import { FormProvider, useController, useForm } from "react-hook-form"; +import { ScorecardViewOptions } from "@hisptz/dhis2-analytics"; +import { RHFCheckboxField } from "@hisptz/dhis2-ui"; + +function AverageDisplayTypeField() { + const { field, fieldState } = useController({ + name: "averageDisplayType", + }); + + return ( + +
+ field.onChange(value)} + name={AverageDisplayType.ALL} + label={i18n.t("All")} + /> + field.onChange(value)} + name={AverageDisplayType.BELOW_AVERAGE} + label={i18n.t("Below Average")} + /> + field.onChange(value)} + name={AverageDisplayType.ABOVE_AVERAGE} + label={i18n.t("Above Average")} + /> +
+
+ ); +} + +export interface ScorecardOptionsModalProps { + hide: boolean; + onClose: () => void; +} + +export function ScorecardOptionsModal({ + hide, + onClose, +}: ScorecardOptionsModalProps) { + const [state, setState] = useScorecardState(); + const initialOptions = state.options; + const form = useForm({ + defaultValues: initialOptions, + }); + + const onUpdate = (options: ScorecardViewOptions) => { + setState((prevState) => ({ + ...prevState, + options: { + ...prevState.options, + ...options, + }, + })); + onClose(); + }; + + return ( + + + {i18n.t("Options")} + +
+

{i18n.t("Visibility")}

+
+ + + + + + + + +
+

{i18n.t("Average")}

+ +

{i18n.t("Options")}

+
+ + +
+
+
+ + + + + + +
+
+ ); +} diff --git a/packages/app/src/modules/Main/components/ScorecardViewPage/state/state.tsx b/packages/app/src/modules/Main/components/ScorecardViewPage/state/state.tsx index 152a1b715..e87650fbe 100644 --- a/packages/app/src/modules/Main/components/ScorecardViewPage/state/state.tsx +++ b/packages/app/src/modules/Main/components/ScorecardViewPage/state/state.tsx @@ -8,7 +8,7 @@ const ScorecardSetStateContext = createContext(null); export function useScorecardState() { const scorecardState = useContext(ScorecardStateContext)!; const setState = useContext(ScorecardSetStateContext)!; - return [scorecardState, setState]; + return [scorecardState, setState] as [ScorecardState, ScorecardSetState]; } export function ScorecardStateProvider({