dry-ux 1.16.0 → 1.18.0
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.
|
@@ -3,3 +3,12 @@ export declare const importScript: (resourceUrl: string, singleton?: boolean) =>
|
|
|
3
3
|
export declare const importStyleSheet: (resourceUrl: string) => void;
|
|
4
4
|
export declare const useCountdown: (seconds: number, onExpiry: () => void) => number;
|
|
5
5
|
export declare const formatDollar: (amount: number, decimal_places?: boolean) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Calls the authCheckUrl to check if the user is authenticated. The URL should return a JSON response with
|
|
8
|
+
* just `true` or `false` to indicate if the user is authenticated. If user is authenticated, it will call the
|
|
9
|
+
* function (fn), otherwise it will redirect to `authRedirectUrl`.
|
|
10
|
+
* @param fn
|
|
11
|
+
* @param authCheckUrl
|
|
12
|
+
* @param authRedirectUrl
|
|
13
|
+
*/
|
|
14
|
+
export declare const fnWithAuthCheck: (fn: Function, authCheckUrl: string, authRedirectUrl: string) => Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatDollar = exports.useCountdown = exports.importStyleSheet = exports.importScript = exports.preventDefault = void 0;
|
|
3
|
+
exports.fnWithAuthCheck = exports.formatDollar = exports.useCountdown = exports.importStyleSheet = exports.importScript = exports.preventDefault = void 0;
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const preventDefault = (handler) => {
|
|
6
6
|
return (event) => {
|
|
@@ -66,3 +66,22 @@ const formatDollar = (amount, decimal_places) => {
|
|
|
66
66
|
return result;
|
|
67
67
|
};
|
|
68
68
|
exports.formatDollar = formatDollar;
|
|
69
|
+
/**
|
|
70
|
+
* Calls the authCheckUrl to check if the user is authenticated. The URL should return a JSON response with
|
|
71
|
+
* just `true` or `false` to indicate if the user is authenticated. If user is authenticated, it will call the
|
|
72
|
+
* function (fn), otherwise it will redirect to `authRedirectUrl`.
|
|
73
|
+
* @param fn
|
|
74
|
+
* @param authCheckUrl
|
|
75
|
+
* @param authRedirectUrl
|
|
76
|
+
*/
|
|
77
|
+
const fnWithAuthCheck = (fn, authCheckUrl, authRedirectUrl) => fetch(authCheckUrl)
|
|
78
|
+
.then(response => response.json())
|
|
79
|
+
.then(isAuthenticated => {
|
|
80
|
+
if (isAuthenticated) {
|
|
81
|
+
fn();
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
location.href = `${authRedirectUrl}?next=${encodeURIComponent(window.location.pathname)}`;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
exports.fnWithAuthCheck = fnWithAuthCheck;
|
package/dist/ui-utils/Money.js
CHANGED
|
@@ -6,5 +6,5 @@ const utilities_1 = require("../helpers/utilities");
|
|
|
6
6
|
exports.Money = React.memo(({ amount, decimal_places = false, currency = "$" }) => {
|
|
7
7
|
const isNegative = amount < 0;
|
|
8
8
|
const converted = `${currency}${(0, utilities_1.formatDollar)(Math.abs(amount), decimal_places)}`;
|
|
9
|
-
return React.createElement("span", { style: Object.assign({}, (isNegative && { color: "
|
|
9
|
+
return (React.createElement("span", { style: Object.assign({}, (isNegative && { color: "#d9534f" })) }, isNegative ? `(${converted})` : converted));
|
|
10
10
|
});
|