Skip to content

Commit afbabb9

Browse files
jonas-jonasory-bot
authored andcommitted
feat: show settings validation messages as toasts
GitOrigin-RevId: 3df9f7e46afa84acf31aa3e177a2961e5c24c394
1 parent ed2f4fe commit afbabb9

File tree

18 files changed

+189
-38
lines changed

18 files changed

+189
-38
lines changed

package-lock.json

Lines changed: 12 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/elements-react/api-report/elements-react.api.json

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2237,6 +2237,24 @@
22372237
"text": "OryMessageContentProps",
22382238
"canonicalReference": "@ory/elements-react!OryMessageContentProps:type"
22392239
},
2240+
{
2241+
"kind": "Content",
2242+
"text": ">;\n Toast: "
2243+
},
2244+
{
2245+
"kind": "Reference",
2246+
"text": "ComponentType",
2247+
"canonicalReference": "@types/react!React.ComponentType:type"
2248+
},
2249+
{
2250+
"kind": "Content",
2251+
"text": "<"
2252+
},
2253+
{
2254+
"kind": "Reference",
2255+
"text": "OryToastProps",
2256+
"canonicalReference": "@ory/elements-react!OryToastProps:type"
2257+
},
22402258
{
22412259
"kind": "Content",
22422260
"text": ">;\n };\n Page: {\n Header: "
@@ -2269,7 +2287,7 @@
22692287
"name": "OryFlowComponents",
22702288
"typeTokenRange": {
22712289
"startIndex": 1,
2272-
"endIndex": 134
2290+
"endIndex": 138
22732291
}
22742292
},
22752293
{
@@ -3866,6 +3884,41 @@
38663884
"endIndex": 8
38673885
}
38683886
},
3887+
{
3888+
"kind": "TypeAlias",
3889+
"canonicalReference": "@ory/elements-react!OryToastProps:type",
3890+
"docComment": "",
3891+
"excerptTokens": [
3892+
{
3893+
"kind": "Content",
3894+
"text": "type OryToastProps = "
3895+
},
3896+
{
3897+
"kind": "Content",
3898+
"text": "{\n message: "
3899+
},
3900+
{
3901+
"kind": "Reference",
3902+
"text": "UiText",
3903+
"canonicalReference": "@ory/client-fetch!UiText:interface"
3904+
},
3905+
{
3906+
"kind": "Content",
3907+
"text": ";\n id: string | number;\n}"
3908+
},
3909+
{
3910+
"kind": "Content",
3911+
"text": ";"
3912+
}
3913+
],
3914+
"fileUrlPath": "dist/index.d.ts",
3915+
"releaseTag": "Public",
3916+
"name": "OryToastProps",
3917+
"typeTokenRange": {
3918+
"startIndex": 1,
3919+
"endIndex": 4
3920+
}
3921+
},
38693922
{
38703923
"kind": "Function",
38713924
"canonicalReference": "@ory/elements-react!OryTwoStepCard:function(1)",

packages/elements-react/api-report/elements-react.api.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export type OryFlowComponents = {
258258
Message: {
259259
Root: ComponentType<OryMessageRootProps>;
260260
Content: ComponentType<OryMessageContentProps>;
261+
Toast: ComponentType<OryToastProps>;
261262
};
262263
Page: {
263264
Header: ComponentType<OryPageHeaderProps>;
@@ -463,6 +464,12 @@ export type OrySettingsWebauthnProps = {
463464
})[];
464465
};
465466

467+
// @public (undocumented)
468+
export type OryToastProps = {
469+
message: UiText;
470+
id: string | number;
471+
};
472+
466473
// @public (undocumented)
467474
export function OryTwoStepCard(): react_jsx_runtime.JSX.Element;
468475

@@ -497,7 +504,7 @@ export type VerificationFlowContainer = OryFlow<FlowType.Verification, Verificat
497504

498505
// Warnings were encountered during analysis:
499506
//
500-
// dist/index.d.ts:635:5 - (ae-forgotten-export) The symbol "OrySDK" needs to be exported by the entry point index.d.ts
507+
// dist/index.d.ts:645:5 - (ae-forgotten-export) The symbol "OrySDK" needs to be exported by the entry point index.d.ts
501508

502509
// (No @packageDocumentation comment for this package)
503510

packages/elements-react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
"input-otp": "1.4.2",
5151
"react-hook-form": "7.56.4",
5252
"react-intl": "7.1.10",
53+
"sonner": "^2.0.0",
5354
"tailwind-merge": "3.3.0",
54-
"usehooks-ts": "3.1.1",
55-
"zustand": "5.0.4"
55+
"usehooks-ts": "3.1.1"
5656
},
5757
"peerDependencies": {
5858
"react": "^18.0.0 || ^19.0.0 || ^19.0.0-0",

packages/elements-react/src/components/form/form.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,24 @@ export type OryFlowComponents = {
211211
* The Message component is rendered whenever a message is encountered.
212212
*/
213213
Content: ComponentType<OryMessageContentProps>
214+
215+
/**
216+
* The Toast component is rendered for toast messages.
217+
*
218+
* Currently only used in the settings page to display messages.
219+
*/
220+
Toast: ComponentType<OryToastProps>
214221
}
215222
Page: {
216223
Header: ComponentType<OryPageHeaderProps>
217224
}
218225
}
219226

227+
export type OryToastProps = {
228+
message: UiText
229+
id: string | number
230+
}
231+
220232
type DeepPartialTwoLevels<T> = {
221233
[P in keyof T]?: T[P] extends object ? { [K in keyof T[P]]?: T[P][K] } : T[P]
222234
}

packages/elements-react/src/components/settings/settings-card.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import {
5+
getNodeId,
56
isUiNodeScriptAttributes,
67
UiNode,
78
UiNodeGroupEnum,
8-
getNodeId,
99
} from "@ory/client-fetch"
10+
import { useEffect } from "react"
1011
import { useIntl } from "react-intl"
12+
import { Toaster } from "sonner"
1113
import { useComponents, useOryFlow } from "../../context"
14+
import { showToast } from "../../util/showToast"
1215
import { useNodesGroups } from "../../util/ui"
13-
import { OryCardValidationMessages } from "../form"
1416
import { Node } from "../form/nodes/node"
1517
import { OryFormSection } from "../form/section"
1618
import { OrySettingsOidc } from "./oidc-settings"
@@ -160,7 +162,6 @@ export function OrySettingsCard() {
160162

161163
return (
162164
<>
163-
<OryCardValidationMessages />
164165
{scriptNodes.map((n) => (
165166
<Node node={n} key={getNodeId(n)} />
166167
))}
@@ -173,6 +174,28 @@ export function OrySettingsCard() {
173174
<SettingsSectionContent key={group} group={group} nodes={nodes} />
174175
)
175176
})}
177+
<SettingsMessageToaster />
176178
</>
177179
)
178180
}
181+
182+
function SettingsMessageToaster() {
183+
const { flow } = useOryFlow()
184+
const { Message } = useComponents()
185+
186+
useEffect(() => {
187+
if (!flow.ui.messages) {
188+
return
189+
}
190+
flow.ui.messages.forEach((message) => {
191+
showToast(
192+
{
193+
message,
194+
},
195+
Message.Toast,
196+
)
197+
})
198+
}, [flow.ui.messages, Message.Toast])
199+
200+
return <Toaster />
201+
}

packages/elements-react/src/locales/de.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@
255255
"settings.title-totp": "Verwalten Sie die Authentifikator-App",
256256
"settings.title-webauthn": "Hardware-Token verwalten",
257257
"settings.webauthn.info": "Hardware-Tokens werden für die Zweitfaktor-Authentifizierung oder als Erstfaktor-Authentifizierung mit Passkeys verwendet",
258+
"settings.messages.toast-title.success": "Einstellungen aktualisiert",
259+
"settings.messages.toast-title.error": "Fehler beim Aktualisieren der Einstellungen",
258260
"card.footer.select-another-method": "Eine andere Methode verwenden",
259261
"account-linking.title": "Account verbinden",
260262
"property.email": "E-Mail",

packages/elements-react/src/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@
209209
"settings.profile.description": "Update your profile information",
210210
"settings.webauthn.title": "Manage Hardware Tokens",
211211
"settings.webauthn.description": "Manage your hardware token settings",
212+
"settings.messages.toast-title.success": "Settings updated",
213+
"settings.messages.toast-title.error": "Could not update settings",
212214
"verification.registration-button": "Sign up",
213215
"verification.registration-label": "Don't have an account?",
214216
"verification.title": "Verify your account",

packages/elements-react/src/locales/es.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@
202202
"settings.profile.title": "Configuración de Perfil",
203203
"settings.webauthn.description": "Administra la configuración de tu token de hardware",
204204
"settings.webauthn.title": "Gestionar Tokens de Hardware",
205+
"settings.messages.toast-title.success": "Configuración actualizada con éxito",
206+
"settings.messages.toast-title.error": "Error al actualizar la configuración",
205207
"consent.title": "Autorizar {party}",
206208
"consent.subtitle": "Una aplicación de terceros quiere acceder a la información asociada a su cuenta {identifier}.",
207209
"consent.scope.openid.title": "Identidad",

packages/elements-react/src/locales/fr.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@
244244
"settings.profile.description": "Mettre à jour les informations de votre profil",
245245
"settings.webauthn.title": "Gérer les jetons matériels",
246246
"settings.webauthn.description": "Gérer les paramètres de votre jeton matériel",
247+
"settings.messages.toast-title.success": "Paramètres mis à jour avec succès",
248+
"settings.messages.toast-title.error": "Échec de la mise à jour des paramètres",
247249
"verification.subtitle": "Saisissez l'adresse e-mail associée à votre compte pour la vérifier",
248250
"input.placeholder": "Saisissez votre {placeholder}",
249251
"card.header.parts.oidc": "un fournisseur de réseaux sociaux",

0 commit comments

Comments
 (0)