From b9e407ad53717bc5f5a3124c6560f854ce1f11bb Mon Sep 17 00:00:00 2001 From: Razze Date: Sun, 20 Aug 2023 16:13:48 +0200 Subject: [PATCH] Refactor modal and use it for safety rating --- frontend/public/locales/en/common.json | 1 + frontend/src/components/Modal.tsx | 149 ++++++++++++------ .../application/AppDevelopersControls.tsx | 44 ++++-- .../components/application/SafetyRating.tsx | 108 ++++--------- 4 files changed, 163 insertions(+), 139 deletions(-) diff --git a/frontend/public/locales/en/common.json b/frontend/public/locales/en/common.json index ddfbdbc8b..7bc454748 100644 --- a/frontend/public/locales/en/common.json +++ b/frontend/public/locales/en/common.json @@ -1,4 +1,5 @@ { + "close": "Close", "go-home": "Go Home", "search-apps": "Search apps", "publish": "Publish", diff --git a/frontend/src/components/Modal.tsx b/frontend/src/components/Modal.tsx index 957bb9872..45eb7c2ed 100644 --- a/frontend/src/components/Modal.tsx +++ b/frontend/src/components/Modal.tsx @@ -2,75 +2,130 @@ import { Dialog, Transition } from "@headlessui/react" import { Fragment, FunctionComponent } from "react" import Button from "./Button" import { useTranslation } from "react-i18next" +import { HiXMark } from "react-icons/hi2" +import clsx from "clsx" interface Props { shown: boolean - submitButtonText: string - isSubmitButtonDisabled?: boolean - onSubmit: () => void - cancelButtonText?: string - onCancel: () => void title: string - description: string + centerTitle?: boolean + description?: string + onClose: () => void children?: React.ReactNode + cancelButton?: { + label?: string + onClick: () => void + disabled?: boolean + } + submitButton?: { + label?: string + onClick: () => void + disabled?: boolean + } } const Modal: FunctionComponent = ({ shown, - submitButtonText, - isSubmitButtonDisabled, - onSubmit, - cancelButtonText = "cancel", - onCancel, title, + centerTitle, description, + onClose, children, + cancelButton, + submitButton, }) => { const { t } = useTranslation() return ( <> - - { - onCancel() - }} - > - - - - -
- - -
-
- - -
- -
-
+ setIsOpen(false)} + title={t(`appname-is-safety-rating-${highestSafetyRating}`, { + appName: data.name, + })} + > + <> +
+ +
+
+ b.safetyRating - a.safetyRating) + .map(({ description, safetyRating, icon }, i) => ({ + id: i, + header: t(description), + icon: ( - - {t(`appname-is-safety-rating-${highestSafetyRating}`, { - appName: data.name, - })} - -
- b.safetyRating - a.safetyRating) - .map(({ description, safetyRating, icon }, i) => ({ - id: i, - header: t(description), - icon: ( - - ), - }))} - /> -
    -
    -
    - - -
    + ), + }))} + />
    -
    -
    + + ) }