nexus-shared 1.1.18 → 1.1.19
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.
- package/package.json +1 -1
- package/src/client.ts +2 -1
- package/src/components/documents/button.tsx +5 -1
- package/src/components/inputs/input-box.tsx +4 -2
- package/src/components/inputs/input-form.tsx +126 -14
- package/src/helpers/browser-helpers.tsx +41 -1
- package/src/helpers/input-helpers.tsx +34 -4
- package/src/helpers/validation-helpers.tsx +302 -0
- package/src/index.ts +2 -18
- package/src/interface.ts +4 -1
- package/src/interfaces/button-interfaces.tsx +2 -2
- package/src/interfaces/http-interfaces.tsx +89 -8
- package/src/interfaces/input-interfaces.tsx +61 -11
- package/src/interfaces/message-interfaces.tsx +32 -0
- package/src/interfaces/storage-interfaces.tsx +1 -0
- package/src/interfaces/type-interfaces.tsx +8 -2
- package/src/interfaces/user-interfaces.tsx +17 -0
- package/src/nexus.environments.tsx +6 -1
- package/src/proxy-api/proxy-backend.tsx +60 -0
- package/src/proxy-api/proxy-constants.tsx +28 -0
- package/src/proxy-api/proxy-helpers.tsx +91 -0
- package/src/proxy-api-client.tsx +1 -0
- package/src/proxy-api-server.tsx +2 -0
- package/src/services/http-client-services.tsx +26 -11
- package/src/services/http-services.tsx +37 -22
- package/src/services/loader-service.tsx +5 -4
- package/src/services/localstorage-service.tsx +59 -0
- package/src/services/message-services.tsx +383 -0
- package/src/sso-config/auth-token-validation.ts +20 -0
- package/src/sso-config/callback-route.tsx +34 -0
- package/src/sso-config/cookie-encryption.ts +51 -0
- package/src/sso-config/cookie-helpers.tsx +77 -0
- package/src/sso-config/forgot-password-route.tsx +36 -0
- package/src/sso-config/oauth-callback-state.ts +58 -0
- package/src/sso-config/pkce-helpers.ts +16 -0
- package/src/sso-config/provider-complete-route.tsx +15 -0
- package/src/sso-config/redirect-context-actions.tsx +46 -0
- package/src/sso-config/redirect-context-helpers.tsx +144 -0
- package/src/sso-config/redirect-context-persist.tsx +18 -0
- package/src/sso-config/redirect-context-route.tsx +45 -0
- package/src/sso-config/refresh-route.tsx +22 -0
- package/src/sso-config/sign-in-route.tsx +69 -0
- package/src/sso-config/sign-out-route.tsx +53 -0
- package/src/sso-config/sign-up-route.tsx +46 -0
- package/src/sso-config/sso-backend-flow.ts +45 -0
- package/src/sso-config/sso-complete-route.tsx +46 -0
- package/src/sso-config/sso-config.ts +57 -0
- package/src/{interfaces → sso-config}/sso-interfaces.tsx +17 -1
- package/src/sso-config/sso-response-helpers.tsx +20 -0
- package/src/sso-server.tsx +21 -1
- package/src/styles/nexus.dialog.css +3 -0
- package/src/load-env.ts +0 -2
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -24,8 +24,9 @@ export * from "./helpers/browser-helpers";
|
|
|
24
24
|
export * from "./services/http-client-services";
|
|
25
25
|
export * from "./services/loader-service";
|
|
26
26
|
export * from "./services/localstorage-service";
|
|
27
|
+
export * from "./services/message-services";
|
|
27
28
|
export * from "./services/theme-service";
|
|
28
29
|
// Core
|
|
29
30
|
export * from "./nexus-client";
|
|
31
|
+
export * from "./proxy-api-client";
|
|
30
32
|
export * from "./sso-client";
|
|
31
|
-
|
|
@@ -42,11 +42,15 @@ export const CreateButton = (param: IButton, parent?: HTMLElement | UN, styles?:
|
|
|
42
42
|
|
|
43
43
|
SetElementStyles(button, styles);
|
|
44
44
|
|
|
45
|
-
button.className = DEFAULT_BUTTON_CLASS(param.columnSize,
|
|
45
|
+
button.className = DEFAULT_BUTTON_CLASS(param.columnSize ?? 0, 0, param.borderSize, param.background ?? NEXUS_CONFIG.DEFAULT_BACKGROUND, param.defaultClass, needColumnSize);
|
|
46
46
|
const span = document.createElement("span");
|
|
47
47
|
span.textContent = param.label instanceof Function ? (param.label(param.data) ?? null) : (param.label ?? null);
|
|
48
48
|
button.appendChild(span);
|
|
49
49
|
button.onclick = (e) => param.onClick?.(e, button, param.data, param.displayOrder);
|
|
50
|
+
button.style.height = "var(--IH)";
|
|
51
|
+
|
|
52
|
+
button.classList.add("df", "ac", "pl5", "pr5");
|
|
53
|
+
|
|
50
54
|
if (param.url) {
|
|
51
55
|
(button as HTMLAnchorElement).href = param.url;
|
|
52
56
|
(button as HTMLAnchorElement).target = param.target ?? ETargets.Blank;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { INPUT_ICON_BOX_CLASS } from "../../helpers/input-helpers";
|
|
1
2
|
import { DEFAULT_INPUT_BORDER_SIZE, IInputRootParameters, REQUIRED_TEXT1 } from "../../interfaces/input-interfaces";
|
|
2
3
|
import { EBackgrounds } from "../../interfaces/theme-interfaces";
|
|
3
4
|
import { NEXUS_CONFIG } from "../../nexus.environments";
|
|
@@ -16,7 +17,7 @@ export const CreateInputBox = (param: IInputRootParameters<any>, child: HTMLElem
|
|
|
16
17
|
if (param.label && !isTabular) {
|
|
17
18
|
const label = document.createElement("label");
|
|
18
19
|
label.className = "pa t50 ty50 left ilb en anim ml2";
|
|
19
|
-
label.innerHTML = param.label + ((param as any).isRequired ? `<span class="
|
|
20
|
+
label.innerHTML = param.label + ((param as any).isRequired ? `<span style="color: var(--B13)" class="fs-08 ml1">${REQUIRED_TEXT1}</span>` : "");
|
|
20
21
|
label.htmlFor = param.id;
|
|
21
22
|
box.appendChild(label);
|
|
22
23
|
}
|
|
@@ -24,7 +25,8 @@ export const CreateInputBox = (param: IInputRootParameters<any>, child: HTMLElem
|
|
|
24
25
|
if (param.icon) {
|
|
25
26
|
box.classList.add("df", "ac");
|
|
26
27
|
const I = param.icon;
|
|
27
|
-
CreateIconBox(I.icon, box, null, null, I.type, I.background ?? param.background ?? EBackgrounds.None, I.boxSize, I.iconSize, null, null, null, null, I.opacity, null, null, null, null, I.onClicked, I.onMouseEnter, (I.onClicked || I.onMouseEnter) !== undefined);
|
|
28
|
+
const iconBox = CreateIconBox(I.icon, box, null, null, I.type, I.background ?? param.background ?? EBackgrounds.None, I.boxSize, I.iconSize, null, null, null, null, I.opacity, null, null, null, null, I.onClicked, I.onMouseEnter, (I.onClicked || I.onMouseEnter) !== undefined);
|
|
29
|
+
iconBox.classList.add(INPUT_ICON_BOX_CLASS);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
if (parent) parent.appendChild(box);
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
2
|
|
|
3
3
|
import React, { useEffect } from "react";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { HideLoader, ShowLoader, SubmitApi, WarningMessage } from "../../client";
|
|
5
|
+
import { GetInputId, SetResponseErrorMessage } from "../../helpers/input-helpers";
|
|
6
|
+
import { IsValidInputs } from "../../helpers/validation-helpers";
|
|
7
|
+
import { EActions, EAnimationClasses, EBackgrounds, EButtonTypes, EFlexPositions, EIcons, EIconTypes, ESizes, GetApiInformations, GetButton, UN, VoidCallbackHandler } from "../../interface";
|
|
8
|
+
import { DEFAULT_ROW_GAP, EInputTypes, GetForms, IApiForm, IForm, IFormCreateResults, IInputCreateResults, ISubmitForm, ISubmitFormCreateResults, OnFormChangeHandler, OnFormSubmitHandler } from "../../interfaces/input-interfaces";
|
|
9
|
+
import { GetFormButtonPosition } from "../../services/localstorage-service";
|
|
10
|
+
import { CreateButton } from "../documents/button";
|
|
6
11
|
import { CreateInputs, DisposeInputs } from "./input";
|
|
7
12
|
|
|
8
13
|
const forceChangeDefaultValue = (inputResults: IInputCreateResults[], newDefaultValue: any): boolean => {
|
|
@@ -16,37 +21,144 @@ const forceChangeDefaultValue = (inputResults: IInputCreateResults[], newDefault
|
|
|
16
21
|
}
|
|
17
22
|
return isChanged;
|
|
18
23
|
};
|
|
19
|
-
export const CreateForm = (param: IForm, rowGap?: number): IFormCreateResults | null => {
|
|
20
|
-
const { inputs, onChanged, index, isTabularForm,
|
|
24
|
+
export const CreateForm = (param: IForm, parentIdentifier: HTMLElement | string | UN, rowGap?: number, onFormRendered?: VoidCallbackHandler): IFormCreateResults | null => {
|
|
25
|
+
const { inputs, onChanged, index, isTabularForm, defaultValue } = param;
|
|
21
26
|
const parentElement = typeof parentIdentifier === "string" ? document.getElementById(parentIdentifier) : parentIdentifier;
|
|
22
27
|
|
|
23
28
|
if (!parentElement || inputs.length === 0 || !onChanged) {
|
|
24
29
|
//TODO: WarningMessage("Invalid Inputs", "Please provide valid inputs, onChanged function and parent element.");
|
|
25
30
|
return null;
|
|
26
31
|
}
|
|
32
|
+
const rowElement = document.createElement("div");
|
|
33
|
+
if (parentElement) parentElement.appendChild(rowElement);
|
|
27
34
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
parent.style.paddingTop = "var(--IEM)";
|
|
31
|
-
if (parentElement) parentElement.appendChild(parent);
|
|
35
|
+
rowElement.className = `row g${rowGap ?? DEFAULT_ROW_GAP} sb fg`;
|
|
36
|
+
rowElement.style.paddingTop = "var(--IEM)";
|
|
32
37
|
|
|
33
|
-
const inputResults = CreateInputs(inputs, onChanged, index, isTabularForm,
|
|
38
|
+
const inputResults = CreateInputs(inputs, onChanged, index, isTabularForm, rowElement, defaultValue);
|
|
39
|
+
|
|
40
|
+
onFormRendered?.(inputResults);
|
|
34
41
|
|
|
35
42
|
return {
|
|
36
43
|
inputResults: inputResults,
|
|
37
|
-
formElement:
|
|
44
|
+
formElement: rowElement,
|
|
38
45
|
dispose: (invokeOnChanged?: boolean) => {
|
|
39
46
|
DisposeInputs(inputResults, invokeOnChanged);
|
|
40
|
-
|
|
47
|
+
rowElement.remove();
|
|
41
48
|
},
|
|
42
49
|
forceChangeDefaultValue: (newDefaultValue: any) => forceChangeDefaultValue(inputResults, newDefaultValue),
|
|
43
50
|
} as IFormCreateResults;
|
|
44
51
|
};
|
|
45
52
|
|
|
46
|
-
export const Form = ({ param, rowGap }: { param: IForm; rowGap?: number }): React.ReactNode => {
|
|
53
|
+
export const Form = ({ param, parentIdentifier, rowGap, onFormRendered }: { param: IForm; parentIdentifier: HTMLElement | string | UN; rowGap?: number; onFormRendered?: VoidCallbackHandler }): React.ReactNode => {
|
|
47
54
|
useEffect(() => {
|
|
48
|
-
const formResults = CreateForm(param, rowGap);
|
|
55
|
+
const formResults = CreateForm(param, parentIdentifier, rowGap, onFormRendered);
|
|
49
56
|
return () => formResults?.dispose();
|
|
50
57
|
}, [param, rowGap]);
|
|
51
58
|
return <React.Fragment></React.Fragment>;
|
|
52
59
|
};
|
|
60
|
+
|
|
61
|
+
export const CreateSubmitForm = (param: ISubmitForm, parentIdentifier: HTMLElement | string | UN, rowGap?: number, buttonPosition?: EFlexPositions, formAction?: EActions | UN, onFormRendered?: VoidCallbackHandler): ISubmitFormCreateResults | null => {
|
|
62
|
+
const parentElement = typeof parentIdentifier === "string" ? document.getElementById(parentIdentifier) : parentIdentifier;
|
|
63
|
+
buttonPosition = buttonPosition ?? GetFormButtonPosition();
|
|
64
|
+
|
|
65
|
+
if (!parentElement || !param.inputs || param.inputs.length === 0 || !param.onSubmit) return null;
|
|
66
|
+
|
|
67
|
+
let formValue: any | UN;
|
|
68
|
+
let defaultValue: any | UN = GetApiInformations.IS_API(param.defaultValue) ? null : param.defaultValue;
|
|
69
|
+
const onChangedHandler: OnFormChangeHandler = (currentValue, isInitilizing, isForcedChanged, isDisposed, currentKey, index, type, dataSource) => {
|
|
70
|
+
formValue = currentValue;
|
|
71
|
+
if (param.onChanged) param.onChanged(currentValue, isInitilizing, isForcedChanged, isDisposed, currentKey, index, type, dataSource);
|
|
72
|
+
};
|
|
73
|
+
const onFormSubmit = async (event: Event) => {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
const isValidForm = IsValidInputs(formResults?.inputResults, formValue, true, true);
|
|
76
|
+
const isValid = param.overrideValidation ? await param.overrideValidation(formValue, isValidForm, formResults, formAction) : isValidForm;
|
|
77
|
+
|
|
78
|
+
param.onSubmit({ ...formValue }, isValidForm, event, formResults!, defaultValue);
|
|
79
|
+
if (!isValid) WarningMessage("Invalid Inputs", "Please fill all required fields correctly.");
|
|
80
|
+
};
|
|
81
|
+
const formParameters = GetForms.FORM(param.inputs, onChangedHandler, defaultValue);
|
|
82
|
+
const formElement = document.createElement("form");
|
|
83
|
+
parentElement.appendChild(formElement);
|
|
84
|
+
const formResults = CreateForm(formParameters, formElement, rowGap, onFormRendered);
|
|
85
|
+
if (!formResults) return null;
|
|
86
|
+
formResults.formElement.classList.add("h100", "fg");
|
|
87
|
+
|
|
88
|
+
const submitButton = param.inputs.find((input) => input.inputType === EInputTypes.SubmitButton);
|
|
89
|
+
if (!submitButton) {
|
|
90
|
+
const buttonStyle: React.CSSProperties = {
|
|
91
|
+
width: "fit-content",
|
|
92
|
+
};
|
|
93
|
+
const DEFAULT_BUTTON_CLASS = "col- jc r";
|
|
94
|
+
rowGap = rowGap ?? DEFAULT_ROW_GAP;
|
|
95
|
+
const PADDING = rowGap * 2;
|
|
96
|
+
|
|
97
|
+
const buttonParam = GetButton("Submit", null, null, EIcons.SAVE, null, null, EBackgrounds.PrimaryColor, DEFAULT_BUTTON_CLASS, null, EIconTypes.FILLED, null, 0, null, EButtonTypes.SUBMIT);
|
|
98
|
+
const buttonContainer = document.createElement("div");
|
|
99
|
+
buttonContainer.className = `df ac pt1 pb5 ${buttonPosition} bb pr${PADDING} pl${PADDING}`;
|
|
100
|
+
buttonContainer.style.minHeight = "calc(var(--IH) * 1.5)";
|
|
101
|
+
|
|
102
|
+
formElement.appendChild(buttonContainer);
|
|
103
|
+
CreateButton(buttonParam, buttonContainer, buttonStyle, false);
|
|
104
|
+
|
|
105
|
+
if (param.onCancelClick) {
|
|
106
|
+
const buttonParam = GetButton("Cancel", null, null, EIcons.CLOSE, param.onCancelClick, null, EBackgrounds.ErrorColor, DEFAULT_BUTTON_CLASS + ` ml${PADDING}`, null, EIconTypes.FILLED, null, 0, null, EButtonTypes.BUTTON);
|
|
107
|
+
CreateButton(buttonParam, buttonContainer, buttonStyle, false);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
formElement.className = `df ddc w100 h100 oh fg pr`;
|
|
112
|
+
formElement.addEventListener("submit", onFormSubmit);
|
|
113
|
+
|
|
114
|
+
const onDispose = () => {
|
|
115
|
+
formResults?.dispose();
|
|
116
|
+
formElement.remove();
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
formElement: formElement,
|
|
121
|
+
dispose: () => onDispose(),
|
|
122
|
+
formObject: formResults,
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const SubmitForm = ({ param, parentIdentifier, rowGap, buttonPosition, formAction, onFormRendered }: { param: ISubmitForm; parentIdentifier: HTMLElement | string | UN; rowGap?: number; buttonPosition?: EFlexPositions; formAction?: EActions | UN; onFormRendered?: VoidCallbackHandler }): React.ReactNode => {
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
const submitForm = CreateSubmitForm(param, parentIdentifier, rowGap, buttonPosition, formAction, onFormRendered);
|
|
129
|
+
return () => submitForm?.dispose();
|
|
130
|
+
}, [param, parentIdentifier, rowGap, buttonPosition, formAction]);
|
|
131
|
+
return <React.Fragment></React.Fragment>;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const CreateApiForm = (param: IApiForm, parentIdentifier: HTMLElement | string | UN, rowGap?: number, buttonPosition?: EFlexPositions, formAction?: EActions | UN, overrideLoaderParend?: HTMLElement | string | UN, successMessage?: boolean | UN, errorMessage?: boolean | UN, onFormRendered?: VoidCallbackHandler): ISubmitFormCreateResults | null => {
|
|
135
|
+
let isLoading = false;
|
|
136
|
+
const onFormSubmit: OnFormSubmitHandler = async (currentValue, isValidForm, event, form, defaultValue) => {
|
|
137
|
+
if (isLoading) return;
|
|
138
|
+
isLoading = true;
|
|
139
|
+
|
|
140
|
+
if (param.onSubmit) param.onSubmit(currentValue, isValidForm, event, form, defaultValue);
|
|
141
|
+
if (!isValidForm) return;
|
|
142
|
+
|
|
143
|
+
const loaderParent = overrideLoaderParend ?? submitForm?.formElement ?? parentIdentifier;
|
|
144
|
+
ShowLoader(loaderParent, EAnimationClasses.SPIN, true, ESizes.Normal, null, null, null, "r");
|
|
145
|
+
const apiResponse = await SubmitApi(param.api, currentValue, successMessage, errorMessage);
|
|
146
|
+
if (!apiResponse.isSuccess) SetResponseErrorMessage(apiResponse, submitForm?.formObject.inputResults);
|
|
147
|
+
HideLoader(loaderParent);
|
|
148
|
+
param.onApiSubmit(currentValue, apiResponse, submitForm!, defaultValue);
|
|
149
|
+
isLoading = false;
|
|
150
|
+
};
|
|
151
|
+
const submitFormParam = GetForms.SUBMITFORM(param?.inputs, onFormSubmit, param?.defaultValue, param?.overrideValidation, param?.onChanged, param?.onCancelClick);
|
|
152
|
+
const submitForm = CreateSubmitForm(submitFormParam, parentIdentifier, rowGap, buttonPosition, formAction, onFormRendered);
|
|
153
|
+
if (!submitForm) return null;
|
|
154
|
+
|
|
155
|
+
return submitForm;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
export const ApiForm = ({ param, parentIdentifier, rowGap, buttonPosition, formAction, overrideLoaderParend, successMessage, errorMessage, onFormRendered }: { param: IApiForm; parentIdentifier: HTMLElement | string | UN; rowGap?: number; buttonPosition?: EFlexPositions; formAction?: EActions | UN; overrideLoaderParend?: HTMLElement | string | UN; successMessage?: boolean | UN; errorMessage?: boolean | UN; onFormRendered?: VoidCallbackHandler }): React.ReactNode => {
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
const apiForm = CreateApiForm(param, parentIdentifier, rowGap, buttonPosition, formAction, overrideLoaderParend, successMessage, errorMessage, onFormRendered);
|
|
161
|
+
return () => apiForm?.dispose();
|
|
162
|
+
}, [param, parentIdentifier, rowGap, buttonPosition, formAction, overrideLoaderParend, successMessage, errorMessage]);
|
|
163
|
+
return <React.Fragment></React.Fragment>;
|
|
164
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UN } from "../interface";
|
|
1
2
|
import { EAnimationClasses } from "../interfaces/layout-interfaces";
|
|
2
3
|
import { NEXUS_INFO } from "../nexus.environments";
|
|
3
4
|
import { EKeyModifier, EKeys } from "./../interfaces/browser-interfaces";
|
|
@@ -6,7 +7,7 @@ import { Debounce } from "./utility-helpers";
|
|
|
6
7
|
|
|
7
8
|
export const IsBrowser = (): boolean => typeof window !== "undefined" && typeof document !== "undefined";
|
|
8
9
|
|
|
9
|
-
export const RemoveElement = async (elementIdentity: string | HTMLElement, timeout?: number, animation?: EAnimationClasses): Promise<boolean> => {
|
|
10
|
+
export const RemoveElement = async (elementIdentity: string | HTMLElement, timeout?: number | UN, animation?: EAnimationClasses | UN): Promise<boolean> => {
|
|
10
11
|
return new Promise(async (resolve) => {
|
|
11
12
|
if (!IsBrowser() || !elementIdentity) return resolve(false);
|
|
12
13
|
else if (typeof elementIdentity === "string") {
|
|
@@ -69,3 +70,42 @@ export const FindChildElements = (parent: HTMLElement, childSelector: string, sh
|
|
|
69
70
|
return children.length > 0 ? [children[0]] : [];
|
|
70
71
|
}
|
|
71
72
|
};
|
|
73
|
+
export const PxToRem = (px: number): number => {
|
|
74
|
+
const fontSize = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
75
|
+
return Math.round((px / fontSize) * 1000) / 1000;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const ConvertColorToRGBA = (color: string, alpha: number = 0.1): string => {
|
|
79
|
+
if (!color) return "rgba(0, 0, 0, 0.1)";
|
|
80
|
+
|
|
81
|
+
let finalColor = color.trim();
|
|
82
|
+
if (finalColor.startsWith("var(")) finalColor = finalColor.replace(/^var\(\s*/, "").replace(/\s*\)$/, "");
|
|
83
|
+
// CSS Variable Support
|
|
84
|
+
if (finalColor.startsWith("--")) finalColor = getComputedStyle(document.documentElement).getPropertyValue(finalColor).trim();
|
|
85
|
+
|
|
86
|
+
// Create temporary element for browser auto parsing
|
|
87
|
+
const temp = document.createElement("div");
|
|
88
|
+
temp.style.color = finalColor;
|
|
89
|
+
|
|
90
|
+
document.body.appendChild(temp);
|
|
91
|
+
|
|
92
|
+
const computed = getComputedStyle(temp).color;
|
|
93
|
+
|
|
94
|
+
document.body.removeChild(temp);
|
|
95
|
+
|
|
96
|
+
// computed => rgb(...) or rgba(...)
|
|
97
|
+
const match = computed.match(/rgba?\(\s*(\d+)[,\s]+(\d+)[,\s]+(\d+)(?:[,\s\/]+([\d.]+))?\s*\)/i);
|
|
98
|
+
|
|
99
|
+
if (!match) return "rgba(0, 0, 0, 1)";
|
|
100
|
+
|
|
101
|
+
const r = parseInt(match[1], 10);
|
|
102
|
+
const g = parseInt(match[2], 10);
|
|
103
|
+
const b = parseInt(match[3], 10);
|
|
104
|
+
|
|
105
|
+
let a = match[4] !== undefined ? parseFloat(match[4]) : 1;
|
|
106
|
+
|
|
107
|
+
// Override alpha if provided
|
|
108
|
+
if (alpha) a = alpha;
|
|
109
|
+
|
|
110
|
+
return `rgba(${r}, ${g}, ${b}, ${a})`;
|
|
111
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { DEFAULT_ICON_ELEMENT_NAME } from "../interface";
|
|
1
|
+
import { DEFAULT_ICON_ELEMENT_NAME, IErrorRespose } from "../interface";
|
|
2
2
|
import { EValueChangeTypes, IInputCreateResults, IInputRootParameters } from "../interfaces/input-interfaces";
|
|
3
3
|
import { ESizes } from "../interfaces/layout-interfaces";
|
|
4
4
|
import { UN } from "../interfaces/type-interfaces";
|
|
5
|
+
import { AddRemoveErrorFromInput } from "./validation-helpers";
|
|
5
6
|
|
|
7
|
+
export const INPUT_ICON_BOX_CLASS = "input-icon-box";
|
|
6
8
|
export const GetParentKey = (parentKey?: string | null) => {
|
|
7
9
|
if (parentKey) return parentKey.split("|")[0];
|
|
8
10
|
return undefined;
|
|
@@ -23,22 +25,50 @@ export const ForceSetValue = (input?: IInputCreateResults | null, value?: any |
|
|
|
23
25
|
clearTimeout(timeoutValue);
|
|
24
26
|
}, timeout ?? 0);
|
|
25
27
|
};
|
|
28
|
+
|
|
29
|
+
export const ApplyPasswordInputs = (inputResults: IInputCreateResults[] | UN, selectors: string[] | UN) => {
|
|
30
|
+
if (!inputResults || inputResults.length === 0 || !selectors || selectors.length === 0) return;
|
|
31
|
+
for (const selector of selectors) {
|
|
32
|
+
const input = inputResults.find((x) => x.input.id === selector);
|
|
33
|
+
if (input) ApplyPasswordInput(input.rootElement.querySelector(`div.ib.${INPUT_ICON_BOX_CLASS}`), input.inputElement);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
26
37
|
export const ApplyPasswordInput = (iconbox: HTMLElement | null, inputElement: HTMLElement | null) => {
|
|
27
38
|
const input = inputElement as HTMLInputElement | undefined;
|
|
28
39
|
if (!input || !iconbox) return;
|
|
40
|
+
|
|
41
|
+
if (!iconbox.classList.contains("h")) iconbox.classList.add("h");
|
|
42
|
+
|
|
29
43
|
const icon = iconbox.querySelector(DEFAULT_ICON_ELEMENT_NAME) as HTMLElement | null;
|
|
30
|
-
if (icon)
|
|
44
|
+
if (!icon) return;
|
|
31
45
|
const onMouseLeave = () => {
|
|
32
46
|
iconbox.removeEventListener("mouseleave", onMouseLeave);
|
|
33
47
|
iconbox.removeEventListener("click", onClicked);
|
|
34
48
|
input.type = "password";
|
|
35
49
|
if (icon) icon.setAttribute("name", "key");
|
|
36
50
|
};
|
|
51
|
+
const onMouseEnter = () => {
|
|
52
|
+
icon.setAttribute("name", "eye");
|
|
53
|
+
iconbox.addEventListener("mouseleave", onMouseLeave);
|
|
54
|
+
iconbox.addEventListener("click", onClicked);
|
|
55
|
+
};
|
|
37
56
|
const onClicked = () => {
|
|
38
57
|
const isPassword = input.type === "password";
|
|
39
58
|
input.type = isPassword ? "text" : "password";
|
|
40
59
|
if (icon) icon.setAttribute("name", isPassword ? "eye-off" : "eye");
|
|
41
60
|
};
|
|
42
|
-
iconbox.addEventListener("
|
|
43
|
-
|
|
61
|
+
iconbox.addEventListener("mouseenter", onMouseEnter);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const SetResponseErrorMessage = (apiResponse: IErrorRespose, inputResults: IInputCreateResults[] | UN) => {
|
|
65
|
+
if (!apiResponse || !inputResults || inputResults.length === 0 || !apiResponse.inputName) return;
|
|
66
|
+
|
|
67
|
+
const inputKeys = apiResponse.inputName.toLowerCase().split("|");
|
|
68
|
+
let isFirstElement = true;
|
|
69
|
+
for (const inputKey of inputKeys) {
|
|
70
|
+
const input = inputResults.find((x) => GetInputId(x.input).toLowerCase() === inputKey);
|
|
71
|
+
if (input) AddRemoveErrorFromInput(input.input, input.inputElement, true, apiResponse.message, isFirstElement);
|
|
72
|
+
isFirstElement = false;
|
|
73
|
+
}
|
|
44
74
|
};
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { EInputTypes, ICheckbox, IDate, IInputCreateResults, IInputParameters, IInputRootParameters, INumber, ISelection, ITablularForm, ITextbox, RegexTypes, UN } from "../interface";
|
|
2
|
+
import { BitwiseToList } from "./bitwise-helpers";
|
|
3
|
+
import { GetInputId } from "./input-helpers";
|
|
4
|
+
import { IsNullOrEmpty, MakeFirstLetterUpperCase } from "./string-helpers";
|
|
5
|
+
|
|
6
|
+
export const MAX_INPUT_TYPE = 1900;
|
|
7
|
+
export const MAX_HINT_LENGTH = 5;
|
|
8
|
+
|
|
9
|
+
export const IsValidInputs = (inputObjects: IInputCreateResults[] | UN, inputFormValues: any, isAutoError: boolean, isAutoFocus: boolean): boolean => {
|
|
10
|
+
let isValid = true;
|
|
11
|
+
if (!inputObjects || inputObjects.length === 0) return true;
|
|
12
|
+
const sortedObjects = [...inputObjects].sort((a, b) => b.input.displayOrder - a.input.displayOrder);
|
|
13
|
+
for (const obj of sortedObjects) {
|
|
14
|
+
// Skip unsupported input types
|
|
15
|
+
if (obj.input.inputType >= MAX_INPUT_TYPE) continue;
|
|
16
|
+
|
|
17
|
+
const inputId = GetInputId(obj.input);
|
|
18
|
+
const inputValue = inputFormValues?.[inputId] ?? null;
|
|
19
|
+
const isValidInput = IsValidInput(obj, inputValue, isAutoError, isAutoFocus);
|
|
20
|
+
if (isValid) isValid = isValidInput;
|
|
21
|
+
}
|
|
22
|
+
return isValid;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const IsValidInput = (inputObject: IInputCreateResults, inputValue: any, isAutoError: boolean, isAutoFocus: boolean): boolean => {
|
|
26
|
+
const input = inputObject.inputElement;
|
|
27
|
+
const inputParameters = inputObject.input;
|
|
28
|
+
const value = inputValue;
|
|
29
|
+
|
|
30
|
+
switch (inputParameters.inputType) {
|
|
31
|
+
//---------------------
|
|
32
|
+
case EInputTypes.Textbox:
|
|
33
|
+
case EInputTypes.Textarea:
|
|
34
|
+
case EInputTypes.Texteditor:
|
|
35
|
+
return IsValidTextbox(inputParameters as ITextbox, value, isAutoFocus, isAutoError, input);
|
|
36
|
+
//---------------------
|
|
37
|
+
case EInputTypes.Checkbox:
|
|
38
|
+
return IsValidCheck(inputParameters as ICheckbox, value as boolean, isAutoFocus, isAutoError, input);
|
|
39
|
+
//---------------------
|
|
40
|
+
case EInputTypes.MultiSelection:
|
|
41
|
+
case EInputTypes.SingleSelection:
|
|
42
|
+
return IsValidSelectionbox(inputParameters as ISelection, value, isAutoFocus, isAutoError, input);
|
|
43
|
+
//---------------------
|
|
44
|
+
case EInputTypes.Datepicker:
|
|
45
|
+
return IsValidDate(inputParameters as IDate, value as Date | UN, isAutoFocus, isAutoError, input);
|
|
46
|
+
//---------------------
|
|
47
|
+
case EInputTypes.Number:
|
|
48
|
+
return IsValidNumber(inputParameters as INumber, value as number | UN, isAutoFocus, isAutoError, input);
|
|
49
|
+
//---------------------
|
|
50
|
+
case EInputTypes.TabularForm:
|
|
51
|
+
return IsValidTabularform(inputParameters as ITablularForm, value as any[], isAutoFocus, isAutoError, input);
|
|
52
|
+
//---------------------
|
|
53
|
+
case EInputTypes.Radiobox:
|
|
54
|
+
return true;
|
|
55
|
+
|
|
56
|
+
default:
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// ------------- Start Textbox Validation -------------
|
|
62
|
+
function IsValidTextbox<T>(inputParameters: ITextbox, value: T | UN, isNeedFocus: boolean, isAutoError: boolean, input: HTMLElement | UN): boolean {
|
|
63
|
+
if (!inputParameters) return false;
|
|
64
|
+
return IsValidInputValueWithRegex(inputParameters, input, inputParameters.validatorKey, value as string | UN, inputParameters.minLength ?? 0, inputParameters.maxLength ?? 0, isAutoError, isNeedFocus, inputParameters.regexKey).isValid;
|
|
65
|
+
}
|
|
66
|
+
export function IsValidInputValueWithRegex(inputParameters: ITextbox, input: HTMLElement | UN, key: string | UN, value: string | UN, min: number, max: number, isAutoError: boolean = true, isNeedFocus: boolean, regularExpression: RegexTypes | UN): IValidationMessage {
|
|
67
|
+
const valid = IsValidInputValueWithLength(inputParameters, input, key, value, min, max, false, isNeedFocus);
|
|
68
|
+
if (Array.isArray(regularExpression)) {
|
|
69
|
+
if (IsNullOrEmpty(value)) return { isValid: false, message: InvalidValueMessage(key) };
|
|
70
|
+
|
|
71
|
+
const isMatch = regularExpression.includes(value as string);
|
|
72
|
+
const msg = !isMatch ? `${InvalidValueMessage(key)}\nOnly allowed values are: ${MakeFirstLetterUpperCase(regularExpression.slice(0, MAX_HINT_LENGTH).join(", "))}${regularExpression.length > MAX_HINT_LENGTH ? `...` : "."}` : null;
|
|
73
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, !isMatch, msg, isNeedFocus);
|
|
74
|
+
|
|
75
|
+
return { isValid: isMatch, message: msg };
|
|
76
|
+
} else if (typeof regularExpression === "string") {
|
|
77
|
+
const isMatch = IsMatchRejex(value, regularExpression);
|
|
78
|
+
if (!isMatch) {
|
|
79
|
+
const msg = InvalidValueMessage(key ?? "Input-Value");
|
|
80
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, true, msg, isNeedFocus);
|
|
81
|
+
return { isValid: isMatch, message: msg };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!valid.isValid) {
|
|
86
|
+
AddRemoveErrorFromInput(inputParameters, input, isAutoError, valid.message, isNeedFocus);
|
|
87
|
+
return valid;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (regularExpression && (regularExpression as string) !== "") {
|
|
91
|
+
const isMatch = IsMatchRejex(value, regularExpression);
|
|
92
|
+
if (!isMatch) {
|
|
93
|
+
const msg = InvalidValueMessage(key ?? "Input-Value");
|
|
94
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, true, msg, isNeedFocus);
|
|
95
|
+
return { isValid: isMatch, message: msg };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, false);
|
|
99
|
+
return { isValid: true, message: "Valid" };
|
|
100
|
+
}
|
|
101
|
+
export function IsValidInputValueWithLength(inputParameters: IInputParameters<any>, input: HTMLElement | UN, key: string | UN, value: string | UN, min: number, max: number, isAutoError: boolean = true, isNeedFocus: boolean): IValidationMessage {
|
|
102
|
+
if (IsNullOrEmpty(value) && min > 0) {
|
|
103
|
+
const mes = RequiredMessage(key);
|
|
104
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, true, mes, isNeedFocus);
|
|
105
|
+
return { isValid: false, message: mes };
|
|
106
|
+
}
|
|
107
|
+
value = value ?? "";
|
|
108
|
+
if (min > 0 && value.length < min) {
|
|
109
|
+
const mes = MinLengthNotValidMessage(key ?? "Input-Value", min, false);
|
|
110
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, true, mes, isNeedFocus);
|
|
111
|
+
return { isValid: false, message: mes };
|
|
112
|
+
} else if (max > 0 && value.length > max) {
|
|
113
|
+
const mes = MaxLengthNotValidMessage(key ?? "Input-Value", max, false);
|
|
114
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, true, mes, isNeedFocus);
|
|
115
|
+
return { isValid: false, message: mes };
|
|
116
|
+
}
|
|
117
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, false);
|
|
118
|
+
return { isValid: true, message: "Valid" };
|
|
119
|
+
}
|
|
120
|
+
// ------------- End Textbox Validation -------------
|
|
121
|
+
|
|
122
|
+
// ------------- Start Checkbox Validation -------------
|
|
123
|
+
function IsValidCheck(inputParameters: ICheckbox, value: boolean, isNeedFocus: boolean, isAutoError: boolean, input: HTMLElement | UN): boolean {
|
|
124
|
+
if (!inputParameters) return false;
|
|
125
|
+
if (!value) {
|
|
126
|
+
if (inputParameters.isRequired) {
|
|
127
|
+
const requiredMessage = RequiredMessage(inputParameters.validatorKey);
|
|
128
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, true, requiredMessage, isNeedFocus);
|
|
129
|
+
return false;
|
|
130
|
+
} else {
|
|
131
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, false, undefined, isNeedFocus);
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, false, undefined, isNeedFocus);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
// ------------- End Checkbox Validation -------------
|
|
140
|
+
|
|
141
|
+
// ------------- Start Selectionbox Validation -------------
|
|
142
|
+
function IsValidSelectionbox(inputParameters: ISelection, value: any | UN, isNeedFocus: boolean, isAutoError: boolean, input: HTMLElement | UN): boolean {
|
|
143
|
+
let isValid = true;
|
|
144
|
+
const isMulti = inputParameters.inputType === EInputTypes.MultiSelection;
|
|
145
|
+
if (!inputParameters) isValid = false;
|
|
146
|
+
else if (!inputParameters.isRequired) isValid = true;
|
|
147
|
+
else isValid = isMulti ? value?.length > 0 : value !== null;
|
|
148
|
+
|
|
149
|
+
if (!isValid && isMulti && inputParameters.bitwiseEnum !== undefined && inputParameters.bitwiseEnum !== null) isValid = BitwiseToList(inputParameters.bitwiseEnum, value).length > 0;
|
|
150
|
+
|
|
151
|
+
if (isValid) {
|
|
152
|
+
AddRemoveErrorFromInput(inputParameters, input, false);
|
|
153
|
+
return isValid;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const msg = RequiredMessage(inputParameters.validatorKey ?? "Input-Value");
|
|
157
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, true, msg, isNeedFocus);
|
|
158
|
+
return isValid;
|
|
159
|
+
}
|
|
160
|
+
// ------------- End Selectionbox Validation -------------
|
|
161
|
+
|
|
162
|
+
// ------------- Start Date Validation -------------
|
|
163
|
+
function IsValidDate(inputParameters: IDate, value: Date | UN, isNeedFocus: boolean, isAutoError: boolean, input: HTMLElement | UN): boolean {
|
|
164
|
+
if (!inputParameters) return false;
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
// ------------- End Date Validation -------------
|
|
168
|
+
|
|
169
|
+
// ------------- Start Number Validation -------------
|
|
170
|
+
function IsValidNumber(inputParameters: INumber, value: number | UN, isNeedFocus: boolean, isAutoError: boolean, input: HTMLElement | UN): boolean {
|
|
171
|
+
if (!inputParameters) return false;
|
|
172
|
+
if (value === null || value === undefined) {
|
|
173
|
+
if (inputParameters.isRequired) {
|
|
174
|
+
const requiredMessage = RequiredMessage(inputParameters.validatorKey);
|
|
175
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, true, requiredMessage, isNeedFocus);
|
|
176
|
+
return false;
|
|
177
|
+
} else {
|
|
178
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, false, undefined, isNeedFocus);
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (inputParameters.minLength !== undefined && inputParameters.minLength !== null && value < inputParameters.minLength) {
|
|
184
|
+
const msg = MinLengthNotValidMessage(inputParameters.validatorKey ?? "Input", inputParameters.minLength, false);
|
|
185
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, true, msg, isNeedFocus);
|
|
186
|
+
return false;
|
|
187
|
+
} else if (inputParameters.maxLength !== undefined && inputParameters.maxLength !== null && value > inputParameters.maxLength) {
|
|
188
|
+
const msg = MaxLengthNotValidMessage(inputParameters.validatorKey ?? "Input", inputParameters.maxLength, false);
|
|
189
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, true, msg, isNeedFocus);
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (isAutoError) AddRemoveErrorFromInput(inputParameters, input, false, undefined, isNeedFocus);
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
// ------------- End Number Validation -------------
|
|
197
|
+
|
|
198
|
+
// ------------- Start Tabularform Validation -------------
|
|
199
|
+
function IsValidTabularform(inputParameters: ITablularForm, value: any[], isNeedFocus: boolean, isAutoError: boolean, input: HTMLElement | UN) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
// ------------- End Tabularform Validation -------------
|
|
203
|
+
|
|
204
|
+
// ------------- Starting Input Error Handling -------------
|
|
205
|
+
export const AddRemoveErrorFromInput = (inputParameters: IInputRootParameters<any>, input: HTMLElement | UN, isShowError: boolean, errorMessage?: string | UN, isNeedFocus?: boolean) => {
|
|
206
|
+
if (!input) return;
|
|
207
|
+
const formGroup = input.parentElement;
|
|
208
|
+
if (!formGroup) return;
|
|
209
|
+
|
|
210
|
+
const errorMessageTitle_Class = "input-error-message-popup";
|
|
211
|
+
if ((formGroup as any).cleanup) (formGroup as any).cleanup();
|
|
212
|
+
const formWrapper = formGroup.parentElement;
|
|
213
|
+
if (isShowError) {
|
|
214
|
+
formGroup.classList.add("error");
|
|
215
|
+
const errorMessageTitle = GetValidationMessage(inputParameters);
|
|
216
|
+
//const errorMessageBox = CreateTitle(errorMessageTitle, formGroup);
|
|
217
|
+
//errorMessageBox.titleElement.classList.add(errorMessageTitle_Class);
|
|
218
|
+
if (formWrapper && formWrapper.classList.contains("ipt-wp")) ShowError(input, formWrapper, errorMessage, isNeedFocus);
|
|
219
|
+
else if (formGroup.classList.contains("ipt-wp")) ShowError(input, formGroup, errorMessage, isNeedFocus);
|
|
220
|
+
} else {
|
|
221
|
+
formGroup.classList.remove("error");
|
|
222
|
+
if (formWrapper && formWrapper.classList.contains("ipt-wp")) formWrapper.querySelector(".msg")?.remove();
|
|
223
|
+
else if (formGroup.classList.contains("ipt-wp")) formGroup.querySelector(".msg")?.remove();
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const ShowError = (input: HTMLElement, formWrapper: HTMLElement, errorMessage?: string | UN, isNeedFocus?: boolean) => {
|
|
227
|
+
formWrapper.querySelector(".msg")?.remove();
|
|
228
|
+
const p = document.createElement("p") as HTMLParagraphElement;
|
|
229
|
+
p.classList.add("msg", "fw500", "fs-08");
|
|
230
|
+
p.style.color = "var(--B13)";
|
|
231
|
+
errorMessage = errorMessage ?? "Input is not valid";
|
|
232
|
+
p.innerHTML = errorMessage;
|
|
233
|
+
p.setAttribute("nlt", errorMessage ?? "");
|
|
234
|
+
formWrapper.querySelector(".smb")?.appendChild(p);
|
|
235
|
+
if (isNeedFocus) input.focus();
|
|
236
|
+
};
|
|
237
|
+
// ------------- End Input Error Handling -------------
|
|
238
|
+
interface IValidationMessage {
|
|
239
|
+
message: string | UN;
|
|
240
|
+
isValid: boolean;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export const IsMatchRejex = (value?: string | UN, reg?: string | UN): boolean => {
|
|
244
|
+
if (!reg) return true;
|
|
245
|
+
const regex = new RegExp(reg);
|
|
246
|
+
return regex.test(value ?? "");
|
|
247
|
+
};
|
|
248
|
+
export function RequiredMessage(key?: string | UN) {
|
|
249
|
+
return IsNullOrEmpty(key) ? "Invalid Request, Required validation error." : `Invalid Request, ${MakeFirstLetterUpperCase(key ?? "")} is Required.`;
|
|
250
|
+
}
|
|
251
|
+
export function GetValidationMessage(inputParams: IInputRootParameters<any>): string {
|
|
252
|
+
const messages: string[] = [];
|
|
253
|
+
const param = inputParams as IInputParameters<any>;
|
|
254
|
+
|
|
255
|
+
if (param.isRequired) {
|
|
256
|
+
messages.push("This field is required.");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (param.minLength && param.maxLength) messages.push(`Must be between ${param.minLength} and ${param.maxLength} characters.`);
|
|
260
|
+
else if (param.minLength) messages.push(`Minimum length is ${param.minLength} characters.`);
|
|
261
|
+
else if (param.maxLength) messages.push(`Maximum length is ${param.maxLength} characters.`);
|
|
262
|
+
|
|
263
|
+
if ((param as any).regexKey) {
|
|
264
|
+
const pattern = (param as any).regexKey;
|
|
265
|
+
|
|
266
|
+
if (pattern === "^[a-zA-Z0-9_]+$") messages.push("Only letters, numbers, and underscores are allowed.");
|
|
267
|
+
else if (pattern === "^[0-9]+$") messages.push("Only numbers are allowed.");
|
|
268
|
+
else if (pattern === "^[a-zA-Z]+$") messages.push("Only letters are allowed.");
|
|
269
|
+
else if (pattern === "^[a-zA-Z0-9]+$") messages.push("Only letters and numbers are allowed.");
|
|
270
|
+
else messages.push("Please follow the required format.");
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return messages.join("<br>");
|
|
274
|
+
}
|
|
275
|
+
export function MinLengthNotValidMessage(key: string, min: number, isArrayOrList: boolean = false): string {
|
|
276
|
+
return !isArrayOrList ? `Invalid Request, ${MakeFirstLetterUpperCase(key)} must be at least ${min} characters long.` : `Invalid Request, Please provide at least ${min} ${MakeFirstLetterUpperCase(key)}.`;
|
|
277
|
+
}
|
|
278
|
+
export function MinDateNotValidMessage(key: string, min: Date): string {
|
|
279
|
+
//const formattedDate = EasyDateFormater(min, false);
|
|
280
|
+
const formattedDate = min;
|
|
281
|
+
return `Invalid Request, ${MakeFirstLetterUpperCase(key)} must be on or after ${formattedDate}.`;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function MaxLengthNotValidMessage(key: string, max: number, isArrayOrList: boolean = false, isSelected?: boolean): string {
|
|
285
|
+
const formattedKey = MakeFirstLetterUpperCase(key);
|
|
286
|
+
|
|
287
|
+
if (isArrayOrList) return `You can provide a maximum of ${max} ${formattedKey}.`;
|
|
288
|
+
if (isSelected) return `You cannot select more than ${max} ${formattedKey}.`;
|
|
289
|
+
return `Invalid request: ${formattedKey} cannot exceed ${max} characters.`;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function MaxDateNotValidMessage(key: string, max: Date): string {
|
|
293
|
+
//const formattedDate = EasyDateFormater(max, false);
|
|
294
|
+
const formattedDate = max;
|
|
295
|
+
return `Invalid Request, ${MakeFirstLetterUpperCase(key)} cannot be after ${formattedDate}.`;
|
|
296
|
+
}
|
|
297
|
+
export function InvalidValueMessage(key: string | UN): string {
|
|
298
|
+
return IsNullOrEmpty(key) ? "Invalid Request, Given value is not valid." : `Invalid Request, ${MakeFirstLetterUpperCase(key ?? "")} is not valid.`;
|
|
299
|
+
}
|
|
300
|
+
export function UnauthorizedMessage(key?: string) {
|
|
301
|
+
return IsNullOrEmpty(key) ? "Invalid Request, You haven't permission to access this." : `Invalid Request, You haven't permission to access ${MakeFirstLetterUpperCase(key)}.`;
|
|
302
|
+
}
|