@ory/elements-react 1.0.0-next.19 → 1.0.0-next.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,6 +43,37 @@ import { FlowType } from "@ory/client-fetch";
43
43
  import { useOryFlow } from "@ory/elements-react";
44
44
  import { useFormContext } from "react-hook-form";
45
45
  import { useIntl } from "react-intl";
46
+
47
+ // src/theme/default/utils/url.ts
48
+ function restartFlowUrl(flow, fallback) {
49
+ return flow.request_url || appendReturnTo(fallback, flow.return_to);
50
+ }
51
+ function initFlowUrl(sdkUrl, flowType, flow) {
52
+ const result = `${sdkUrl}/self-service/${flowType}/browser`;
53
+ const qs = new URLSearchParams();
54
+ if (flow.return_to) {
55
+ qs.set("return_to", flow.return_to);
56
+ } else if (typeof window !== "undefined") {
57
+ const searchParams = new URLSearchParams(window.location.search);
58
+ if (searchParams.has("return_to")) {
59
+ qs.set("return_to", searchParams.get("return_to") || "");
60
+ }
61
+ }
62
+ if (qs.toString().length === 0) {
63
+ return result;
64
+ }
65
+ return result + "?" + qs.toString();
66
+ }
67
+ function appendReturnTo(url, returnTo) {
68
+ if (!returnTo) {
69
+ return url;
70
+ }
71
+ const urlObj = new URL(url);
72
+ urlObj.searchParams.set("return_to", returnTo);
73
+ return urlObj.toString();
74
+ }
75
+
76
+ // src/theme/default/components/card/footer.tsx
46
77
  import { Fragment, jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
47
78
  function DefaultCardFooter() {
48
79
  const { flowType } = useOryFlow();
@@ -59,23 +90,12 @@ function DefaultCardFooter() {
59
90
  return null;
60
91
  }
61
92
  }
62
- function getReturnToQueryParam() {
63
- if (typeof window !== "undefined") {
64
- const searchParams = new URLSearchParams(window.location.search);
65
- return searchParams.get("return_to");
66
- }
67
- }
68
93
  function LoginCardFooter() {
69
- const { config, formState } = useOryFlow();
94
+ const { config, formState, flow } = useOryFlow();
70
95
  const intl = useIntl();
71
96
  if (!config.project.registration_enabled || formState.current !== "provide_identifier") {
72
97
  return null;
73
98
  }
74
- let registrationLink = `${config.sdk.url}/self-service/registration/browser`;
75
- const returnTo = getReturnToQueryParam();
76
- if (returnTo) {
77
- registrationLink += `?return_to=${returnTo}`;
78
- }
79
99
  return /* @__PURE__ */ jsxs4("span", { className: "font-normal leading-normal antialiased text-interface-foreground-default-primary", children: [
80
100
  intl.formatMessage({
81
101
  id: "login.registration-label",
@@ -86,7 +106,8 @@ function LoginCardFooter() {
86
106
  "a",
87
107
  {
88
108
  className: "text-button-link-brand-brand transition-colors hover:text-button-link-brand-brand-hover underline",
89
- href: registrationLink,
109
+ href: initFlowUrl(config.sdk.url, "registration", flow),
110
+ "data-testid": "ory/ui/login/link/registration",
90
111
  children: intl.formatMessage({
91
112
  id: "login.registration-button",
92
113
  defaultMessage: "Sign up"
@@ -114,11 +135,6 @@ function RegistrationCardFooter() {
114
135
  setValue("screen", "credential-selection");
115
136
  }
116
137
  }
117
- let loginLink = `${config.sdk.url}/self-service/login/browser`;
118
- const returnTo = getReturnToQueryParam();
119
- if (returnTo) {
120
- loginLink += `?return_to=${returnTo}`;
121
- }
122
138
  return /* @__PURE__ */ jsx4("span", { className: "font-normal leading-normal antialiased", children: formState.current === "method_active" ? /* @__PURE__ */ jsx4(Fragment, { children: screenSelectionNode && /* @__PURE__ */ jsx4(
123
139
  "button",
124
140
  {
@@ -140,7 +156,8 @@ function RegistrationCardFooter() {
140
156
  "a",
141
157
  {
142
158
  className: "text-button-link-brand-brand transition-colors hover:text-button-link-brand-brand-hover underline",
143
- href: loginLink,
159
+ href: initFlowUrl(config.sdk.url, "login", flow),
160
+ "data-testid": "ory/ui/login/link/login",
144
161
  children: intl.formatMessage({
145
162
  id: "registration.login-button",
146
163
  defaultMessage: "Sign in"
@@ -387,12 +404,8 @@ function omit(obj, keys) {
387
404
  // src/theme/default/components/card/current-identifier-button.tsx
388
405
  import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
389
406
  function DefaultCurrentIdentifierButton() {
390
- const {
391
- flow: { ui },
392
- flowType,
393
- config,
394
- formState
395
- } = useOryFlow2();
407
+ const { flow, flowType, config, formState } = useOryFlow2();
408
+ const ui = flow.ui;
396
409
  if (formState.current === "provide_identifier") {
397
410
  return null;
398
411
  }
@@ -400,7 +413,10 @@ function DefaultCurrentIdentifierButton() {
400
413
  if ((nodeBackButton == null ? void 0 : nodeBackButton.attributes.node_type) !== "input" || !nodeBackButton.attributes.value) {
401
414
  return null;
402
415
  }
403
- const initFlowUrl = `${config.sdk.url}/self-service/${flowType}/browser`;
416
+ const initFlowUrl2 = restartFlowUrl(
417
+ flow,
418
+ `${config.sdk.url}/self-service/${flowType}/browser`
419
+ );
404
420
  const attributes = omit(nodeBackButton.attributes, [
405
421
  "autocomplete",
406
422
  "node_type"
@@ -410,8 +426,9 @@ function DefaultCurrentIdentifierButton() {
410
426
  {
411
427
  className: "group inline-flex max-w-full cursor-pointer items-center gap-1 self-start rounded-full border px-[11px] py-[5px] transition-colors border-button-identifier-border-border-default bg-button-identifier-background-default hover:border-button-identifier-border-border-hover hover:bg-button-identifier-background-hover",
412
428
  ...attributes,
413
- href: initFlowUrl,
429
+ href: initFlowUrl2,
414
430
  title: `Adjust ${nodeBackButton == null ? void 0 : nodeBackButton.attributes.value}`,
431
+ "data-testid": "ory/ui/login/link/restart",
415
432
  children: /* @__PURE__ */ jsxs5("span", { className: "inline-flex min-h-5 items-center gap-2 overflow-hidden text-ellipsis", children: [
416
433
  /* @__PURE__ */ jsx6(
417
434
  arrow_left_default,
@@ -786,6 +803,7 @@ function DefaultButtonSocial({
786
803
  value: attributes.value,
787
804
  type: "submit",
788
805
  name: "provider",
806
+ "data-testid": `ory/ui/node/input/${attributes.name}`,
789
807
  ...props,
790
808
  onClick,
791
809
  disabled: isSubmitting,
@@ -931,8 +949,7 @@ function DefaultAuthMethodListItem({
931
949
  className: "flex cursor-pointer gap-3 py-2 text-left items-start",
932
950
  onClick,
933
951
  type: isGroupImmediateSubmit(group) ? "submit" : "button",
934
- id: `auth-method-list-item-${group}`,
935
- "data-testid": "auth-method-list-item",
952
+ "data-testid": `ory/ui/groups/auth-method/${group}`,
936
953
  "aria-label": `Authenticate with ${group}`,
937
954
  children: [
938
955
  /* @__PURE__ */ jsx31("span", { className: "mt-1", children: Icon && /* @__PURE__ */ jsx31(
@@ -1023,9 +1040,6 @@ var DefaultButton = ({
1023
1040
  value,
1024
1041
  name,
1025
1042
  type: type === "button" ? "button" : "submit",
1026
- onSubmit: () => {
1027
- setValue(name, value);
1028
- },
1029
1043
  onClick: (e) => {
1030
1044
  onClick == null ? void 0 : onClick(e);
1031
1045
  if (type !== "button") {
@@ -1077,16 +1091,16 @@ var uiTextToFormattedMessage4 = ({ id, context = {}, text }, intl) => {
1077
1091
  new Date(value),
1078
1092
  /* @__PURE__ */ new Date()
1079
1093
  ),
1080
- [key + "_since_minutes"]: Math.abs(
1094
+ [key + "_since_minutes"]: Math.ceil(
1081
1095
  (value - (/* @__PURE__ */ new Date()).getTime() / 1e3) / 60
1082
- ).toFixed(2),
1096
+ ).toFixed(0),
1083
1097
  [key + "_until"]: intl.formatDateTimeRange(
1084
1098
  /* @__PURE__ */ new Date(),
1085
1099
  new Date(value)
1086
1100
  ),
1087
- [key + "_until_minutes"]: Math.abs(
1101
+ [key + "_until_minutes"]: Math.ceil(
1088
1102
  ((/* @__PURE__ */ new Date()).getTime() / 1e3 - value) / 60
1089
- ).toFixed(2)
1103
+ ).toFixed(0)
1090
1104
  };
1091
1105
  }
1092
1106
  }
@@ -1289,6 +1303,7 @@ var DefaultInput = ({
1289
1303
  maxLength: maxlength,
1290
1304
  autoComplete: autocomplete,
1291
1305
  placeholder: formattedLabel,
1306
+ "data-testid": `ory/ui/node/input/${name}`,
1292
1307
  className: cn(
1293
1308
  "antialiased rounded-forms border leading-tight transition-colors placeholder:h-[20px] placeholder:text-input-foreground-tertiary focus-visible:outline-none focus:ring-0",
1294
1309
  "bg-input-background-default border-input-border-default text-input-foreground-primary",
@@ -1351,6 +1366,7 @@ function DefaultLabel({
1351
1366
  ...messageTestId3(label),
1352
1367
  className: "leading-normal text-input-foreground-primary",
1353
1368
  htmlFor: attributes.name,
1369
+ "data-testid": `ory/ui/node/input/label/${attributes.name}`,
1354
1370
  ...rest,
1355
1371
  children: uiTextToFormattedMessage7(label, intl)
1356
1372
  }
@@ -1359,7 +1375,7 @@ function DefaultLabel({
1359
1375
  /* @__PURE__ */ jsx39(
1360
1376
  "a",
1361
1377
  {
1362
- href: config.project.recovery_ui_url,
1378
+ href: initFlowUrl(config.sdk.url, "recovery", flow),
1363
1379
  className: "text-button-link-brand-brand transition-colors hover:text-button-link-brand-brand-hover underline",
1364
1380
  children: intl.formatMessage({
1365
1381
  id: "forms.label.forgot-password",
@@ -1402,6 +1418,7 @@ var DefaultLinkButton = forwardRef(({ attributes, node }, ref) => {
1402
1418
  ...attributes,
1403
1419
  ref,
1404
1420
  title: label ? uiTextToFormattedMessage8(label, intl) : "",
1421
+ "data-testid": `ory/ui/node/link/${attributes.id}`,
1405
1422
  className: cn(
1406
1423
  "antialiased rounded cursor-pointer text-center border gap-3 leading-none bg-button-primary-background-default hover:bg-button-primary-background-hover transition-colors text-button-primary-foreground-default hover:text-button-primary-foreground-hover p-4 font-medium"
1407
1424
  ),
@@ -1546,8 +1563,15 @@ function DefaultText({ node, attributes }) {
1546
1563
  var _a;
1547
1564
  const intl = useIntl12();
1548
1565
  return /* @__PURE__ */ jsxs26(Fragment3, { children: [
1549
- /* @__PURE__ */ jsx44("p", { "data-testid": `node/text/${attributes.id}/label`, children: node.meta.label ? uiTextToFormattedMessage9(node.meta.label, intl) : "" }),
1550
- (_a = attributes.text.context.secrets) == null ? void 0 : _a.map((text, index) => /* @__PURE__ */ jsx44("pre", { "data-testid": `node/text/lookup_secret_codes/text`, children: /* @__PURE__ */ jsx44("code", { children: text ? uiTextToFormattedMessage9(text, intl) : "" }) }, index))
1566
+ /* @__PURE__ */ jsx44("p", { "data-testid": `ory/ui/node/text/${attributes.id}/label`, children: node.meta.label ? uiTextToFormattedMessage9(node.meta.label, intl) : "" }),
1567
+ (_a = attributes.text.context.secrets) == null ? void 0 : _a.map((text, index) => /* @__PURE__ */ jsx44(
1568
+ "pre",
1569
+ {
1570
+ "data-testid": `ory/ui/node/text/lookup_secret_codes/text`,
1571
+ children: /* @__PURE__ */ jsx44("code", { children: text ? uiTextToFormattedMessage9(text, intl) : "" })
1572
+ },
1573
+ index
1574
+ ))
1551
1575
  ] });
1552
1576
  }
1553
1577
 
@@ -2320,7 +2344,7 @@ function Error({
2320
2344
  error,
2321
2345
  children
2322
2346
  }) {
2323
- return /* @__PURE__ */ jsx63("div", { children: JSON.stringify(error) || children });
2347
+ return /* @__PURE__ */ jsx63("div", { "data-testid": "ory/ui/error/raw", children: JSON.stringify(error) || children });
2324
2348
  }
2325
2349
 
2326
2350
  // src/theme/default/flows/login.tsx