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", "signOut": "Sign out",
"signOutAllDevices": "Sign out all devices", "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.", "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", "somethingWentWrong": "Something went wrong",
"somethingWentWrongDescription": "Sorry, an unexpected error has occurred.", "somethingWentWrongDescription": "Sorry, an unexpected error has occurred.",
"started": "Started", "started": "Started",

View file

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

View file

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