Skip to content

Commit

Permalink
fix: global error message translations
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Sep 6, 2023
1 parent 3889c95 commit 718fe0a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
41 changes: 21 additions & 20 deletions src/react-components/ory/helpers/error-messages.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { UiNode, UiText } from "@ory/client"
import { JSX } from "react"
import { useIntl } from "react-intl"

import { GridStyle, gridStyle, Severity } from "../../../theme"
import { Message, MessageStyleProps } from "../../message"
import { uiTextToFormattedMessage } from "./node"

export type NodeMessagesProps = {
nodes?: UiNode[]
Expand All @@ -11,22 +13,23 @@ export type NodeMessagesProps = {
MessageStyleProps

type nodeMessageProps = {
text: string
id: number
message: UiText
key: string
type: string
} & MessageStyleProps

const nodeMessage = ({ text, id, type, key, ...props }: nodeMessageProps) => (
<Message
key={key}
data-testid={`ui/message/${id}`}
severity={type as Severity}
{...props}
>
{text}
</Message>
)
const nodeMessage = ({ key, message, ...props }: nodeMessageProps) => {
const intl = useIntl()
return (
<Message
key={key}
data-testid={`ui/message/${message.id}`}
severity={message.type as Severity}
{...props}
>
{uiTextToFormattedMessage(message, intl)}
</Message>
)
}

export const NodeMessages = ({
nodes,
Expand All @@ -38,12 +41,10 @@ export const NodeMessages = ({
(groups, { messages }) => {
groups.push(
...messages
.map(({ text, id, type }, key) => {
.map((message, key) => {
return nodeMessage({
text,
id,
type,
key: `node-group-message-${id}-${key}`,
message,
key: `node-group-message-${message.id}-${key}`,
...messageProps,
})
})
Expand All @@ -54,8 +55,8 @@ export const NodeMessages = ({
[],
)

const $messages = uiMessages?.map(({ text, id, type }, key) =>
nodeMessage({ text, id, type, key: `ui-messsage-${id}-${key}` }),
const $messages = uiMessages?.map((message, key) =>
nodeMessage({ message, key: `ui-messsage-${message.id}-${key}` }),
)

const $allMessages = [...($groupMessages || []), ...($messages || [])]
Expand Down
4 changes: 2 additions & 2 deletions src/react-components/ory/helpers/node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export const getNodeLabel = (node: UiNode): UiText | undefined => {
return node.meta.label
}

const uiTextToFormattedMessage = (
{ id, context = {}, text }: UiText,
export const uiTextToFormattedMessage = (
{ id, context = {}, text }: Omit<UiText, "type">,
intl: IntlShape,
) =>
intl.formatMessage(
Expand Down

0 comments on commit 718fe0a

Please sign in to comment.