Pass translated values instead of strings to ContinueCancelModal (#4412)

This commit is contained in:
Jon Koops 2023-02-16 15:50:48 +01:00 committed by GitHub
parent 174b3af6fc
commit f894ca361b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 27 deletions

View file

@ -84,6 +84,7 @@
"signOut": "Sign out",
"signOutAllDevices": "Sign out all devices",
"signOutAllDevicesWarning": "This action will sign out all the devices that have signed in to your account, including the current device you are using.",
"signOutWarning": "Sign out the session?",
"somethingWentWrong": "Something went wrong",
"somethingWentWrongDescription": "Sorry, an unexpected error has occurred.",
"started": "Started",

View file

@ -128,9 +128,9 @@ const DeviceActivity = () => {
{(devices.length > 1 || devices[0].sessions.length > 1) && (
<ContinueCancelModal
buttonTitle="signOutAllDevices"
modalTitle="signOutAllDevices"
modalMessage="signOutAllDevicesWarning"
buttonTitle={t("signOutAllDevices")}
modalTitle={t("signOutAllDevices")}
modalMessage={t("signOutAllDevicesWarning")}
onContinue={() => signOutAll()}
/>
)}
@ -173,10 +173,10 @@ const DeviceActivity = () => {
>
{!session.current && (
<ContinueCancelModal
buttonTitle="doSignOut"
modalTitle="doSignOut"
buttonTitle={t("doSignOut")}
modalTitle={t("doSignOut")}
buttonVariant="secondary"
modalMessage="signOutWarning"
modalMessage={t("signOutWarning")}
onContinue={() => signOutSession(session, device)}
/>
)}

View file

@ -1,5 +1,4 @@
import { ReactNode, useState } from "react";
import { useTranslation } from "react-i18next";
import { Button, ButtonProps, Modal, ModalProps } from "@patternfly/react-core";
export type ContinueCancelModalProps = Omit<ModalProps, "ref" | "children"> & {
@ -24,11 +23,10 @@ export const ContinueCancelModal = ({
onContinue,
continueLabel = "continue",
cancelLabel = "doCancel",
component = "button",
component = Button,
children,
...rest
}: ContinueCancelModalProps) => {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
const Component = component;
@ -39,16 +37,12 @@ export const ContinueCancelModal = ({
onClick={() => setOpen(true)}
isDisabled={isDisabled}
>
{
//@ts-ignore
typeof buttonTitle === "string" ? t(buttonTitle) : buttonTitle
}
{buttonTitle}
</Component>
<Modal
variant="small"
{...rest}
//@ts-ignore
title={t(modalTitle)}
title={modalTitle}
isOpen={open}
onClose={() => setOpen(false)}
actions={[
@ -61,10 +55,7 @@ export const ContinueCancelModal = ({
onContinue();
}}
>
{
//@ts-ignore
t(continueLabel)
}
{continueLabel}
</Button>,
<Button
id="modal-cancel"
@ -72,17 +63,11 @@ export const ContinueCancelModal = ({
variant="secondary"
onClick={() => setOpen(false)}
>
{
//@ts-ignore
t(cancelLabel)
}
{cancelLabel}
</Button>,
]}
>
{
//@ts-ignore
modalMessage ? t(modalMessage) : children
}
{modalMessage ? modalMessage : children}
</Modal>
</>
);