umwd-components 0.1.217 → 0.1.219
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/dist/cjs/components/FooterV2.js +0 -3
- package/dist/cjs/components/StrapiErrors.js +21 -0
- package/dist/cjs/components/SubmitButton.js +37 -0
- package/dist/cjs/components/forms/RegisterForm.js +95 -0
- package/dist/cjs/components/forms/SigninForm.js +89 -0
- package/dist/cjs/data/actions/auth-actions.js +115 -0
- package/dist/cjs/data/services/auth-service.js +51 -0
- package/dist/cjs/index.js +4 -0
- package/dist/esm/components/FooterV2.js +0 -3
- package/dist/esm/components/StrapiErrors.js +19 -0
- package/dist/esm/components/SubmitButton.js +35 -0
- package/dist/esm/components/forms/RegisterForm.js +91 -0
- package/dist/esm/components/forms/SigninForm.js +85 -0
- package/dist/esm/data/actions/auth-actions.js +112 -0
- package/dist/esm/data/services/auth-service.js +48 -0
- package/dist/esm/index.js +2 -0
- package/package.json +3 -2
- package/src/components/FooterV2.tsx +0 -3
- package/src/components/LogoutButton.tsx +12 -0
- package/src/components/StrapiErrors.tsx +12 -0
- package/src/components/SubmitButton.tsx +35 -0
- package/src/components/ZodErrors.tsx +9 -0
- package/src/components/forms/RegisterForm.tsx +118 -0
- package/src/components/forms/SigninForm.tsx +109 -0
- package/src/data/actions/auth-actions.ts +133 -0
- package/src/data/services/auth-service.ts +53 -0
- package/src/index.js +2 -0
- package/src/stories/RegisterForm.stories.js +13 -0
- package/src/stories/SigninForm.stories.js +13 -0
|
@@ -67,7 +67,6 @@ function Footer(_ref) {
|
|
|
67
67
|
md: 4,
|
|
68
68
|
sx: [useIcons && {
|
|
69
69
|
display: "grid",
|
|
70
|
-
alignItems: "center",
|
|
71
70
|
justifyContent: "center"
|
|
72
71
|
}]
|
|
73
72
|
}, /*#__PURE__*/React.createElement(material.Box, {
|
|
@@ -112,7 +111,6 @@ function Footer(_ref) {
|
|
|
112
111
|
md: 4,
|
|
113
112
|
sx: [useIcons && {
|
|
114
113
|
display: "grid",
|
|
115
|
-
alignItems: "center",
|
|
116
114
|
justifyContent: "stretch",
|
|
117
115
|
width: {
|
|
118
116
|
xs: "80%",
|
|
@@ -198,7 +196,6 @@ function Footer(_ref) {
|
|
|
198
196
|
md: 4,
|
|
199
197
|
sx: [useIcons && {
|
|
200
198
|
display: "grid",
|
|
201
|
-
alignItems: "center",
|
|
202
199
|
justifyContent: "center"
|
|
203
200
|
}]
|
|
204
201
|
}, company_socials && company_socials.length > 0 && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(material.Typography, {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* UMWD-Components
|
|
3
|
+
* @copyright Jelle Paulus
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var material = require('@mui/material');
|
|
10
|
+
|
|
11
|
+
function StrapiErrors(_ref) {
|
|
12
|
+
let {
|
|
13
|
+
error
|
|
14
|
+
} = _ref;
|
|
15
|
+
if (!(error !== null && error !== void 0 && error.message)) return null;
|
|
16
|
+
return /*#__PURE__*/React.createElement(material.Alert, {
|
|
17
|
+
severity: "error"
|
|
18
|
+
}, error.message);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.StrapiErrors = StrapiErrors;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*
|
|
3
|
+
* UMWD-Components
|
|
4
|
+
* @copyright Jelle Paulus
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var reactDom = require('react-dom');
|
|
11
|
+
var material = require('@mui/material');
|
|
12
|
+
|
|
13
|
+
function Loader(_ref) {
|
|
14
|
+
let {
|
|
15
|
+
text
|
|
16
|
+
} = _ref;
|
|
17
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
18
|
+
className: "flex items-center space-x-2"
|
|
19
|
+
}, /*#__PURE__*/React.createElement(material.Skeleton, null), /*#__PURE__*/React.createElement("p", null, text));
|
|
20
|
+
}
|
|
21
|
+
function SubmitButton(_ref2) {
|
|
22
|
+
let {
|
|
23
|
+
text,
|
|
24
|
+
loadingText,
|
|
25
|
+
loading
|
|
26
|
+
} = _ref2;
|
|
27
|
+
const status = reactDom.useFormStatus();
|
|
28
|
+
return /*#__PURE__*/React.createElement(material.Button, {
|
|
29
|
+
type: "submit",
|
|
30
|
+
"aria-disabled": status.pending || loading,
|
|
31
|
+
disabled: status.pending || loading
|
|
32
|
+
}, status.pending || loading ? /*#__PURE__*/React.createElement(Loader, {
|
|
33
|
+
text: loadingText
|
|
34
|
+
}) : text);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
exports.SubmitButton = SubmitButton;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*
|
|
3
|
+
* UMWD-Components
|
|
4
|
+
* @copyright Jelle Paulus
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
|
|
12
|
+
var Link = require('next/link');
|
|
13
|
+
var reactDom = require('react-dom');
|
|
14
|
+
var authActions = require('../../data/actions/auth-actions.js');
|
|
15
|
+
var material = require('@mui/material');
|
|
16
|
+
var StrapiErrors = require('../StrapiErrors.js');
|
|
17
|
+
var SubmitButton = require('../SubmitButton.js');
|
|
18
|
+
var styles = require('@mui/material/styles');
|
|
19
|
+
var utils = require('../../lib/utils.js');
|
|
20
|
+
|
|
21
|
+
const INITIAL_STATE = {
|
|
22
|
+
data: null,
|
|
23
|
+
zodErrors: null,
|
|
24
|
+
message: null
|
|
25
|
+
};
|
|
26
|
+
function RegisterForm(_ref) {
|
|
27
|
+
var _formState$zodErrors, _formState$zodErrors2, _formState$zodErrors3, _formState$zodErrors4, _formState$zodErrors5, _formState$zodErrors6;
|
|
28
|
+
let {
|
|
29
|
+
data
|
|
30
|
+
} = _ref;
|
|
31
|
+
const {
|
|
32
|
+
title = "Sign Up",
|
|
33
|
+
subtitle = "Enter your details to create a new account",
|
|
34
|
+
maxWidth,
|
|
35
|
+
sx = {},
|
|
36
|
+
glass = false
|
|
37
|
+
} = data;
|
|
38
|
+
const [formState, formAction] = reactDom.useFormState(authActions.registerUserAction, INITIAL_STATE);
|
|
39
|
+
const theme = styles.useTheme();
|
|
40
|
+
return /*#__PURE__*/React.createElement(material.Container, {
|
|
41
|
+
maxWidth: maxWidth ? maxWidth : "lg",
|
|
42
|
+
sx: {
|
|
43
|
+
my: 1,
|
|
44
|
+
...sx
|
|
45
|
+
}
|
|
46
|
+
}, /*#__PURE__*/React.createElement("form", {
|
|
47
|
+
action: formAction
|
|
48
|
+
}, /*#__PURE__*/React.createElement(material.Card, {
|
|
49
|
+
sx: {
|
|
50
|
+
backdropFilter: "blur(3px)",
|
|
51
|
+
backgroundColor: utils.setOpacity(theme.palette.background.paper, glass ? 0.1 : 1),
|
|
52
|
+
border: glass ? "1px solid rgba(255, 255, 255, 0.15)" : "none"
|
|
53
|
+
}
|
|
54
|
+
}, /*#__PURE__*/React.createElement(material.CardHeader, {
|
|
55
|
+
title: title,
|
|
56
|
+
subheader: subtitle
|
|
57
|
+
}), /*#__PURE__*/React.createElement(material.CardContent, null, /*#__PURE__*/React.createElement(material.Stack, {
|
|
58
|
+
spacing: 2
|
|
59
|
+
}, /*#__PURE__*/React.createElement(material.TextField, {
|
|
60
|
+
id: "username",
|
|
61
|
+
name: "username",
|
|
62
|
+
label: "username",
|
|
63
|
+
variant: "outlined",
|
|
64
|
+
error: (formState === null || formState === void 0 || (_formState$zodErrors = formState.zodErrors) === null || _formState$zodErrors === void 0 ? void 0 : _formState$zodErrors.username) != undefined ? true : false,
|
|
65
|
+
helperText: formState === null || formState === void 0 || (_formState$zodErrors2 = formState.zodErrors) === null || _formState$zodErrors2 === void 0 ? void 0 : _formState$zodErrors2.username
|
|
66
|
+
}), /*#__PURE__*/React.createElement(material.TextField, {
|
|
67
|
+
id: "email",
|
|
68
|
+
name: "email",
|
|
69
|
+
label: "email",
|
|
70
|
+
variant: "outlined",
|
|
71
|
+
error: (formState === null || formState === void 0 || (_formState$zodErrors3 = formState.zodErrors) === null || _formState$zodErrors3 === void 0 ? void 0 : _formState$zodErrors3.email) != undefined ? true : false,
|
|
72
|
+
helperText: formState === null || formState === void 0 || (_formState$zodErrors4 = formState.zodErrors) === null || _formState$zodErrors4 === void 0 ? void 0 : _formState$zodErrors4.email
|
|
73
|
+
}), /*#__PURE__*/React.createElement(material.TextField, {
|
|
74
|
+
id: "password",
|
|
75
|
+
name: "password",
|
|
76
|
+
label: "password",
|
|
77
|
+
variant: "outlined",
|
|
78
|
+
error: (formState === null || formState === void 0 || (_formState$zodErrors5 = formState.zodErrors) === null || _formState$zodErrors5 === void 0 ? void 0 : _formState$zodErrors5.password) != undefined ? true : false,
|
|
79
|
+
helperText: formState === null || formState === void 0 || (_formState$zodErrors6 = formState.zodErrors) === null || _formState$zodErrors6 === void 0 ? void 0 : _formState$zodErrors6.password
|
|
80
|
+
}))), /*#__PURE__*/React.createElement(material.CardActions, null, /*#__PURE__*/React.createElement(SubmitButton.SubmitButton, {
|
|
81
|
+
text: "Sign Up",
|
|
82
|
+
loadingText: "Loading"
|
|
83
|
+
}), /*#__PURE__*/React.createElement(StrapiErrors.StrapiErrors, {
|
|
84
|
+
error: formState === null || formState === void 0 ? void 0 : formState.strapiErrors
|
|
85
|
+
}))), /*#__PURE__*/React.createElement(material.Typography, {
|
|
86
|
+
variant: "body2",
|
|
87
|
+
sx: {
|
|
88
|
+
pt: 2
|
|
89
|
+
}
|
|
90
|
+
}, "Have an account?"), /*#__PURE__*/React.createElement(Link, {
|
|
91
|
+
href: "signin"
|
|
92
|
+
}, "Sing In")));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
exports.default = RegisterForm;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*
|
|
3
|
+
* UMWD-Components
|
|
4
|
+
* @copyright Jelle Paulus
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
11
|
+
|
|
12
|
+
var Link = require('next/link');
|
|
13
|
+
var reactDom = require('react-dom');
|
|
14
|
+
var authActions = require('../../data/actions/auth-actions.js');
|
|
15
|
+
var utils = require('../../lib/utils.js');
|
|
16
|
+
var material = require('@mui/material');
|
|
17
|
+
var SubmitButton = require('../SubmitButton.js');
|
|
18
|
+
var StrapiErrors = require('../StrapiErrors.js');
|
|
19
|
+
var styles = require('@mui/material/styles');
|
|
20
|
+
|
|
21
|
+
const INITIAL_STATE = {
|
|
22
|
+
zodErrors: null,
|
|
23
|
+
strapiErrors: null,
|
|
24
|
+
data: null,
|
|
25
|
+
message: null
|
|
26
|
+
};
|
|
27
|
+
function SigninForm(_ref) {
|
|
28
|
+
var _formState$zodErrors, _formState$zodErrors2, _formState$zodErrors3, _formState$zodErrors4;
|
|
29
|
+
let {
|
|
30
|
+
data
|
|
31
|
+
} = _ref;
|
|
32
|
+
const {
|
|
33
|
+
title = "Sign In",
|
|
34
|
+
subtitle = "Enter your details to sign in to your account",
|
|
35
|
+
maxWidth,
|
|
36
|
+
sx = {},
|
|
37
|
+
glass = false
|
|
38
|
+
} = data;
|
|
39
|
+
const [formState, formAction] = reactDom.useFormState(authActions.loginUserAction, INITIAL_STATE);
|
|
40
|
+
const theme = styles.useTheme();
|
|
41
|
+
return /*#__PURE__*/React.createElement(material.Container, {
|
|
42
|
+
maxWidth: maxWidth ? maxWidth : "lg",
|
|
43
|
+
sx: {
|
|
44
|
+
my: 1,
|
|
45
|
+
...sx
|
|
46
|
+
}
|
|
47
|
+
}, /*#__PURE__*/React.createElement("form", {
|
|
48
|
+
action: formAction
|
|
49
|
+
}, /*#__PURE__*/React.createElement(material.Card, {
|
|
50
|
+
sx: {
|
|
51
|
+
backdropFilter: "blur(3px)",
|
|
52
|
+
backgroundColor: utils.setOpacity(theme.palette.background.paper, glass ? 0.1 : 1),
|
|
53
|
+
border: glass ? "1px solid rgba(255, 255, 255, 0.15)" : "none"
|
|
54
|
+
}
|
|
55
|
+
}, /*#__PURE__*/React.createElement(material.CardHeader, {
|
|
56
|
+
title: title,
|
|
57
|
+
subheader: subtitle
|
|
58
|
+
}), /*#__PURE__*/React.createElement(material.CardContent, null, /*#__PURE__*/React.createElement(material.Stack, {
|
|
59
|
+
spacing: 2
|
|
60
|
+
}, /*#__PURE__*/React.createElement(material.TextField, {
|
|
61
|
+
id: "identifier",
|
|
62
|
+
name: "identifier",
|
|
63
|
+
label: "identifier",
|
|
64
|
+
variant: "outlined",
|
|
65
|
+
error: (formState === null || formState === void 0 || (_formState$zodErrors = formState.zodErrors) === null || _formState$zodErrors === void 0 ? void 0 : _formState$zodErrors.identifier) != undefined ? true : false,
|
|
66
|
+
helperText: formState === null || formState === void 0 || (_formState$zodErrors2 = formState.zodErrors) === null || _formState$zodErrors2 === void 0 ? void 0 : _formState$zodErrors2.identifier
|
|
67
|
+
}), /*#__PURE__*/React.createElement(material.TextField, {
|
|
68
|
+
id: "password",
|
|
69
|
+
name: "password",
|
|
70
|
+
label: "password",
|
|
71
|
+
variant: "outlined",
|
|
72
|
+
error: (formState === null || formState === void 0 || (_formState$zodErrors3 = formState.zodErrors) === null || _formState$zodErrors3 === void 0 ? void 0 : _formState$zodErrors3.password) != undefined ? true : false,
|
|
73
|
+
helperText: formState === null || formState === void 0 || (_formState$zodErrors4 = formState.zodErrors) === null || _formState$zodErrors4 === void 0 ? void 0 : _formState$zodErrors4.password
|
|
74
|
+
}))), /*#__PURE__*/React.createElement(material.CardActions, null, /*#__PURE__*/React.createElement(SubmitButton.SubmitButton, {
|
|
75
|
+
text: "Sign In",
|
|
76
|
+
loadingText: "Loading"
|
|
77
|
+
}), /*#__PURE__*/React.createElement(StrapiErrors.StrapiErrors, {
|
|
78
|
+
error: formState === null || formState === void 0 ? void 0 : formState.strapiErrors
|
|
79
|
+
}))), /*#__PURE__*/React.createElement(material.Typography, {
|
|
80
|
+
sx: {
|
|
81
|
+
pt: 2
|
|
82
|
+
},
|
|
83
|
+
variant: "body2"
|
|
84
|
+
}, "Don't have an account?"), /*#__PURE__*/React.createElement(Link, {
|
|
85
|
+
href: "signup"
|
|
86
|
+
}, "Sign Up")));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exports.default = SigninForm;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
/*
|
|
3
|
+
* UMWD-Components
|
|
4
|
+
* @copyright Jelle Paulus
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
var zod = require('zod');
|
|
11
|
+
var headers = require('next/headers');
|
|
12
|
+
var navigation = require('next/navigation');
|
|
13
|
+
var authService = require('../services/auth-service.js');
|
|
14
|
+
|
|
15
|
+
var _process$env$HOST;
|
|
16
|
+
const config = {
|
|
17
|
+
maxAge: 60 * 60 * 24 * 7,
|
|
18
|
+
// 1 week
|
|
19
|
+
path: "/",
|
|
20
|
+
domain: (_process$env$HOST = process.env.HOST) !== null && _process$env$HOST !== void 0 ? _process$env$HOST : "localhost",
|
|
21
|
+
httpOnly: true,
|
|
22
|
+
secure: process.env.NODE_ENV === "production"
|
|
23
|
+
};
|
|
24
|
+
const schemaRegister = zod.z.object({
|
|
25
|
+
username: zod.z.string().min(3).max(20, {
|
|
26
|
+
message: "Username must be between 3 and 20 characters"
|
|
27
|
+
}),
|
|
28
|
+
password: zod.z.string().min(6).max(100, {
|
|
29
|
+
message: "Password must be between 6 and 100 characters"
|
|
30
|
+
}),
|
|
31
|
+
email: zod.z.string().email({
|
|
32
|
+
message: "Please enter a valid email address"
|
|
33
|
+
})
|
|
34
|
+
});
|
|
35
|
+
async function registerUserAction(prevState, formData) {
|
|
36
|
+
const validatedFields = schemaRegister.safeParse({
|
|
37
|
+
username: formData.get("username"),
|
|
38
|
+
password: formData.get("password"),
|
|
39
|
+
email: formData.get("email")
|
|
40
|
+
});
|
|
41
|
+
if (!validatedFields.success) {
|
|
42
|
+
return {
|
|
43
|
+
...prevState,
|
|
44
|
+
zodErrors: validatedFields.error.flatten().fieldErrors,
|
|
45
|
+
strapiErrors: null,
|
|
46
|
+
message: "Missing Fields. Failed to Register."
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const responseData = await authService.registerUserService(validatedFields.data);
|
|
50
|
+
if (!responseData) {
|
|
51
|
+
return {
|
|
52
|
+
...prevState,
|
|
53
|
+
strapiErrors: null,
|
|
54
|
+
zodErrors: null,
|
|
55
|
+
message: "Ops! Something went wrong. Please try again."
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (responseData.error) {
|
|
59
|
+
return {
|
|
60
|
+
...prevState,
|
|
61
|
+
strapiErrors: responseData.error,
|
|
62
|
+
zodErrors: null,
|
|
63
|
+
message: "Failed to Register."
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
headers.cookies().set("jwt", responseData.jwt, config);
|
|
67
|
+
navigation.redirect("/dashboard");
|
|
68
|
+
}
|
|
69
|
+
const schemaLogin = zod.z.object({
|
|
70
|
+
identifier: zod.z.string().min(3, {
|
|
71
|
+
message: "Identifier must have at least 3 or more characters"
|
|
72
|
+
}).max(20, {
|
|
73
|
+
message: "Please enter a valid username or email address"
|
|
74
|
+
}),
|
|
75
|
+
password: zod.z.string().min(6, {
|
|
76
|
+
message: "Password must have at least 6 or more characters"
|
|
77
|
+
}).max(100, {
|
|
78
|
+
message: "Password must be between 6 and 100 characters"
|
|
79
|
+
})
|
|
80
|
+
});
|
|
81
|
+
async function loginUserAction(prevState, formData) {
|
|
82
|
+
const validatedFields = schemaLogin.safeParse({
|
|
83
|
+
identifier: formData.get("identifier"),
|
|
84
|
+
password: formData.get("password")
|
|
85
|
+
});
|
|
86
|
+
if (!validatedFields.success) {
|
|
87
|
+
return {
|
|
88
|
+
...prevState,
|
|
89
|
+
zodErrors: validatedFields.error.flatten().fieldErrors,
|
|
90
|
+
message: "Missing Fields. Failed to Login."
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
const responseData = await authService.loginUserService(validatedFields.data);
|
|
94
|
+
if (!responseData) {
|
|
95
|
+
return {
|
|
96
|
+
...prevState,
|
|
97
|
+
strapiErrors: responseData.error,
|
|
98
|
+
zodErrors: null,
|
|
99
|
+
message: "Ops! Something went wrong. Please try again."
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
if (responseData.error) {
|
|
103
|
+
return {
|
|
104
|
+
...prevState,
|
|
105
|
+
strapiErrors: responseData.error,
|
|
106
|
+
zodErrors: null,
|
|
107
|
+
message: "Failed to Login."
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
headers.cookies().set("jwt", responseData.jwt, config);
|
|
111
|
+
navigation.redirect("/dashboard");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
exports.loginUserAction = loginUserAction;
|
|
115
|
+
exports.registerUserAction = registerUserAction;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* UMWD-Components
|
|
3
|
+
* @copyright Jelle Paulus
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
var utils = require('../../lib/utils.js');
|
|
10
|
+
|
|
11
|
+
const baseUrl = utils.getStrapiURL();
|
|
12
|
+
async function registerUserService(userData) {
|
|
13
|
+
const url = new URL("/api/auth/local/register", baseUrl);
|
|
14
|
+
try {
|
|
15
|
+
const response = await fetch(url, {
|
|
16
|
+
method: "POST",
|
|
17
|
+
headers: {
|
|
18
|
+
"Content-Type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify({
|
|
21
|
+
...userData
|
|
22
|
+
}),
|
|
23
|
+
cache: "no-cache"
|
|
24
|
+
});
|
|
25
|
+
return response.json();
|
|
26
|
+
} catch (error) {
|
|
27
|
+
console.error("Registration Service Error:", error);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function loginUserService(userData) {
|
|
31
|
+
const url = new URL("/api/auth/local", baseUrl);
|
|
32
|
+
try {
|
|
33
|
+
const response = await fetch(url, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: {
|
|
36
|
+
"Content-Type": "application/json"
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
...userData
|
|
40
|
+
}),
|
|
41
|
+
cache: "no-cache"
|
|
42
|
+
});
|
|
43
|
+
return response.json();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error("Login Service Error:", error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
exports.loginUserService = loginUserService;
|
|
51
|
+
exports.registerUserService = registerUserService;
|
package/dist/cjs/index.js
CHANGED
|
@@ -19,6 +19,8 @@ var WhatsAppClickToChatButton = require('./components/WhatsAppClickToChatButton.
|
|
|
19
19
|
var ScrollLink = require('./components/ScrollLink.js');
|
|
20
20
|
var ScrollNavbar = require('./components/ScrollNavbar.js');
|
|
21
21
|
var FluidBackgroundV2 = require('./components/FluidBackgroundV2.js');
|
|
22
|
+
var RegisterForm = require('./components/forms/RegisterForm.js');
|
|
23
|
+
var SigninForm = require('./components/forms/SigninForm.js');
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
|
|
@@ -35,3 +37,5 @@ exports.WhatsAppClickToChatButton = WhatsAppClickToChatButton.default;
|
|
|
35
37
|
exports.ScrollLink = ScrollLink.default;
|
|
36
38
|
exports.ScrollNavbar = ScrollNavbar.default;
|
|
37
39
|
exports.FluidBackground = FluidBackgroundV2.default;
|
|
40
|
+
exports.RegisterForm = RegisterForm.default;
|
|
41
|
+
exports.SigninForm = SigninForm.default;
|
|
@@ -63,7 +63,6 @@ function Footer(_ref) {
|
|
|
63
63
|
md: 4,
|
|
64
64
|
sx: [useIcons && {
|
|
65
65
|
display: "grid",
|
|
66
|
-
alignItems: "center",
|
|
67
66
|
justifyContent: "center"
|
|
68
67
|
}]
|
|
69
68
|
}, /*#__PURE__*/React__default.createElement(Box, {
|
|
@@ -108,7 +107,6 @@ function Footer(_ref) {
|
|
|
108
107
|
md: 4,
|
|
109
108
|
sx: [useIcons && {
|
|
110
109
|
display: "grid",
|
|
111
|
-
alignItems: "center",
|
|
112
110
|
justifyContent: "stretch",
|
|
113
111
|
width: {
|
|
114
112
|
xs: "80%",
|
|
@@ -194,7 +192,6 @@ function Footer(_ref) {
|
|
|
194
192
|
md: 4,
|
|
195
193
|
sx: [useIcons && {
|
|
196
194
|
display: "grid",
|
|
197
|
-
alignItems: "center",
|
|
198
195
|
justifyContent: "center"
|
|
199
196
|
}]
|
|
200
197
|
}, company_socials && company_socials.length > 0 && /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Typography, {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* UMWD-Components
|
|
3
|
+
* @copyright Jelle Paulus
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Alert } from '@mui/material';
|
|
8
|
+
|
|
9
|
+
function StrapiErrors(_ref) {
|
|
10
|
+
let {
|
|
11
|
+
error
|
|
12
|
+
} = _ref;
|
|
13
|
+
if (!(error !== null && error !== void 0 && error.message)) return null;
|
|
14
|
+
return /*#__PURE__*/React.createElement(Alert, {
|
|
15
|
+
severity: "error"
|
|
16
|
+
}, error.message);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { StrapiErrors };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*
|
|
3
|
+
* UMWD-Components
|
|
4
|
+
* @copyright Jelle Paulus
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useFormStatus } from 'react-dom';
|
|
9
|
+
import { Button, Skeleton } from '@mui/material';
|
|
10
|
+
|
|
11
|
+
function Loader(_ref) {
|
|
12
|
+
let {
|
|
13
|
+
text
|
|
14
|
+
} = _ref;
|
|
15
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
16
|
+
className: "flex items-center space-x-2"
|
|
17
|
+
}, /*#__PURE__*/React.createElement(Skeleton, null), /*#__PURE__*/React.createElement("p", null, text));
|
|
18
|
+
}
|
|
19
|
+
function SubmitButton(_ref2) {
|
|
20
|
+
let {
|
|
21
|
+
text,
|
|
22
|
+
loadingText,
|
|
23
|
+
loading
|
|
24
|
+
} = _ref2;
|
|
25
|
+
const status = useFormStatus();
|
|
26
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
27
|
+
type: "submit",
|
|
28
|
+
"aria-disabled": status.pending || loading,
|
|
29
|
+
disabled: status.pending || loading
|
|
30
|
+
}, status.pending || loading ? /*#__PURE__*/React.createElement(Loader, {
|
|
31
|
+
text: loadingText
|
|
32
|
+
}) : text);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { SubmitButton };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*
|
|
3
|
+
* UMWD-Components
|
|
4
|
+
* @copyright Jelle Paulus
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import Link from 'next/link';
|
|
9
|
+
import { useFormState } from 'react-dom';
|
|
10
|
+
import { registerUserAction } from '../../data/actions/auth-actions.js';
|
|
11
|
+
import { Container, Card, CardHeader, CardContent, Stack, TextField, CardActions, Typography } from '@mui/material';
|
|
12
|
+
import { StrapiErrors } from '../StrapiErrors.js';
|
|
13
|
+
import { SubmitButton } from '../SubmitButton.js';
|
|
14
|
+
import { useTheme } from '@mui/material/styles';
|
|
15
|
+
import { setOpacity } from '../../lib/utils.js';
|
|
16
|
+
|
|
17
|
+
const INITIAL_STATE = {
|
|
18
|
+
data: null,
|
|
19
|
+
zodErrors: null,
|
|
20
|
+
message: null
|
|
21
|
+
};
|
|
22
|
+
function RegisterForm(_ref) {
|
|
23
|
+
var _formState$zodErrors, _formState$zodErrors2, _formState$zodErrors3, _formState$zodErrors4, _formState$zodErrors5, _formState$zodErrors6;
|
|
24
|
+
let {
|
|
25
|
+
data
|
|
26
|
+
} = _ref;
|
|
27
|
+
const {
|
|
28
|
+
title = "Sign Up",
|
|
29
|
+
subtitle = "Enter your details to create a new account",
|
|
30
|
+
maxWidth,
|
|
31
|
+
sx = {},
|
|
32
|
+
glass = false
|
|
33
|
+
} = data;
|
|
34
|
+
const [formState, formAction] = useFormState(registerUserAction, INITIAL_STATE);
|
|
35
|
+
const theme = useTheme();
|
|
36
|
+
return /*#__PURE__*/React.createElement(Container, {
|
|
37
|
+
maxWidth: maxWidth ? maxWidth : "lg",
|
|
38
|
+
sx: {
|
|
39
|
+
my: 1,
|
|
40
|
+
...sx
|
|
41
|
+
}
|
|
42
|
+
}, /*#__PURE__*/React.createElement("form", {
|
|
43
|
+
action: formAction
|
|
44
|
+
}, /*#__PURE__*/React.createElement(Card, {
|
|
45
|
+
sx: {
|
|
46
|
+
backdropFilter: "blur(3px)",
|
|
47
|
+
backgroundColor: setOpacity(theme.palette.background.paper, glass ? 0.1 : 1),
|
|
48
|
+
border: glass ? "1px solid rgba(255, 255, 255, 0.15)" : "none"
|
|
49
|
+
}
|
|
50
|
+
}, /*#__PURE__*/React.createElement(CardHeader, {
|
|
51
|
+
title: title,
|
|
52
|
+
subheader: subtitle
|
|
53
|
+
}), /*#__PURE__*/React.createElement(CardContent, null, /*#__PURE__*/React.createElement(Stack, {
|
|
54
|
+
spacing: 2
|
|
55
|
+
}, /*#__PURE__*/React.createElement(TextField, {
|
|
56
|
+
id: "username",
|
|
57
|
+
name: "username",
|
|
58
|
+
label: "username",
|
|
59
|
+
variant: "outlined",
|
|
60
|
+
error: (formState === null || formState === void 0 || (_formState$zodErrors = formState.zodErrors) === null || _formState$zodErrors === void 0 ? void 0 : _formState$zodErrors.username) != undefined ? true : false,
|
|
61
|
+
helperText: formState === null || formState === void 0 || (_formState$zodErrors2 = formState.zodErrors) === null || _formState$zodErrors2 === void 0 ? void 0 : _formState$zodErrors2.username
|
|
62
|
+
}), /*#__PURE__*/React.createElement(TextField, {
|
|
63
|
+
id: "email",
|
|
64
|
+
name: "email",
|
|
65
|
+
label: "email",
|
|
66
|
+
variant: "outlined",
|
|
67
|
+
error: (formState === null || formState === void 0 || (_formState$zodErrors3 = formState.zodErrors) === null || _formState$zodErrors3 === void 0 ? void 0 : _formState$zodErrors3.email) != undefined ? true : false,
|
|
68
|
+
helperText: formState === null || formState === void 0 || (_formState$zodErrors4 = formState.zodErrors) === null || _formState$zodErrors4 === void 0 ? void 0 : _formState$zodErrors4.email
|
|
69
|
+
}), /*#__PURE__*/React.createElement(TextField, {
|
|
70
|
+
id: "password",
|
|
71
|
+
name: "password",
|
|
72
|
+
label: "password",
|
|
73
|
+
variant: "outlined",
|
|
74
|
+
error: (formState === null || formState === void 0 || (_formState$zodErrors5 = formState.zodErrors) === null || _formState$zodErrors5 === void 0 ? void 0 : _formState$zodErrors5.password) != undefined ? true : false,
|
|
75
|
+
helperText: formState === null || formState === void 0 || (_formState$zodErrors6 = formState.zodErrors) === null || _formState$zodErrors6 === void 0 ? void 0 : _formState$zodErrors6.password
|
|
76
|
+
}))), /*#__PURE__*/React.createElement(CardActions, null, /*#__PURE__*/React.createElement(SubmitButton, {
|
|
77
|
+
text: "Sign Up",
|
|
78
|
+
loadingText: "Loading"
|
|
79
|
+
}), /*#__PURE__*/React.createElement(StrapiErrors, {
|
|
80
|
+
error: formState === null || formState === void 0 ? void 0 : formState.strapiErrors
|
|
81
|
+
}))), /*#__PURE__*/React.createElement(Typography, {
|
|
82
|
+
variant: "body2",
|
|
83
|
+
sx: {
|
|
84
|
+
pt: 2
|
|
85
|
+
}
|
|
86
|
+
}, "Have an account?"), /*#__PURE__*/React.createElement(Link, {
|
|
87
|
+
href: "signin"
|
|
88
|
+
}, "Sing In")));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { RegisterForm as default };
|