umwd-components 0.1.232 → 0.1.234
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/LogoutButton.js +35 -0
- package/dist/cjs/components/dashboard/SideNav.js +28 -3
- package/dist/cjs/data/actions/auth-actions.js +8 -0
- package/dist/cjs/index.js +2 -0
- package/dist/esm/components/LogoutButton.js +31 -0
- package/dist/esm/components/dashboard/SideNav.js +28 -3
- package/dist/esm/data/actions/auth-actions.js +8 -1
- package/dist/esm/index.js +1 -0
- package/package.json +1 -1
- package/src/components/LogoutButton.tsx +57 -6
- package/src/components/dashboard/SideNav.tsx +51 -14
- package/src/index.js +1 -0
- package/src/stories/LogoutButton.stories.js +15 -0
- package/src/stories/SideNav.stories.js +10 -0
|
@@ -0,0 +1,35 @@
|
|
|
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 React = require('react');
|
|
13
|
+
var authActions = require('../data/actions/auth-actions.js');
|
|
14
|
+
var material = require('@mui/material');
|
|
15
|
+
var LogoutIcon = require('@mui/icons-material/Logout');
|
|
16
|
+
|
|
17
|
+
//
|
|
18
|
+
function LogoutButton(_ref) {
|
|
19
|
+
let {
|
|
20
|
+
text = "Log out",
|
|
21
|
+
variant = "text"
|
|
22
|
+
} = _ref;
|
|
23
|
+
return /*#__PURE__*/React.createElement("form", {
|
|
24
|
+
action: authActions.logoutAction
|
|
25
|
+
}, /*#__PURE__*/React.createElement(material.Button, {
|
|
26
|
+
type: "submit"
|
|
27
|
+
// aria-disabled={status.pending || loading}
|
|
28
|
+
// disabled={status.pending || loading}
|
|
29
|
+
,
|
|
30
|
+
startIcon: /*#__PURE__*/React.createElement(LogoutIcon, null),
|
|
31
|
+
variant: variant
|
|
32
|
+
}, text));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.default = LogoutButton;
|
|
@@ -182,7 +182,13 @@ function SideNav(_ref) {
|
|
|
182
182
|
}
|
|
183
183
|
}, /*#__PURE__*/React__namespace.createElement(material.IconButton, {
|
|
184
184
|
onClick: handleDrawerClose
|
|
185
|
-
}, theme.direction === "rtl" ? /*#__PURE__*/React__namespace.createElement(iconsMaterial.ChevronRight, null) : /*#__PURE__*/React__namespace.createElement(iconsMaterial.ChevronLeft, null))), /*#__PURE__*/React__namespace.createElement(material.Divider, null), sections.map((section, index) => /*#__PURE__*/React__namespace.createElement(
|
|
185
|
+
}, theme.direction === "rtl" ? /*#__PURE__*/React__namespace.createElement(iconsMaterial.ChevronRight, null) : /*#__PURE__*/React__namespace.createElement(iconsMaterial.ChevronLeft, null))), /*#__PURE__*/React__namespace.createElement(material.Divider, null), sections.map((section, index) => /*#__PURE__*/React__namespace.createElement(material.Box, {
|
|
186
|
+
sx: {
|
|
187
|
+
display: "flex",
|
|
188
|
+
flexDirection: "column",
|
|
189
|
+
alignItems: "flex-start"
|
|
190
|
+
}
|
|
191
|
+
}, /*#__PURE__*/React__namespace.createElement(Link, {
|
|
186
192
|
key: index,
|
|
187
193
|
href: section.link,
|
|
188
194
|
passHref: true
|
|
@@ -194,11 +200,30 @@ function SideNav(_ref) {
|
|
|
194
200
|
p: 1,
|
|
195
201
|
cursor: "pointer"
|
|
196
202
|
}
|
|
197
|
-
}, section.icon, open && /*#__PURE__*/React__namespace.createElement(material.Typography, {
|
|
203
|
+
}, section.icon, !open && section.subSections && /*#__PURE__*/React__namespace.createElement(material.Typography, null, "..."), open && /*#__PURE__*/React__namespace.createElement(material.Typography, {
|
|
198
204
|
sx: {
|
|
199
205
|
pl: 2
|
|
200
206
|
}
|
|
201
|
-
}, section.title)))
|
|
207
|
+
}, section.title))), section.subSections && open && section.subSections.map((subSection, index) => {
|
|
208
|
+
return /*#__PURE__*/React__namespace.createElement(Link, {
|
|
209
|
+
key: index,
|
|
210
|
+
href: subSection.link,
|
|
211
|
+
passHref: true
|
|
212
|
+
}, /*#__PURE__*/React__namespace.createElement(material.Box, {
|
|
213
|
+
sx: {
|
|
214
|
+
display: "flex",
|
|
215
|
+
alignItems: "center",
|
|
216
|
+
justifyContent: "center",
|
|
217
|
+
p: 1,
|
|
218
|
+
cursor: "pointer"
|
|
219
|
+
}
|
|
220
|
+
}, /*#__PURE__*/React__namespace.createElement(material.Typography, {
|
|
221
|
+
variant: "body2",
|
|
222
|
+
sx: {
|
|
223
|
+
pl: 4
|
|
224
|
+
}
|
|
225
|
+
}, subSection.title)));
|
|
226
|
+
})))), /*#__PURE__*/React__namespace.createElement(material.Box, {
|
|
202
227
|
component: "main",
|
|
203
228
|
sx: {
|
|
204
229
|
flexGrow: 1,
|
|
@@ -110,6 +110,14 @@ async function loginUserAction(prevState, formData) {
|
|
|
110
110
|
headers.cookies().set("jwt", responseData.jwt, config);
|
|
111
111
|
navigation.redirect("/dashboard");
|
|
112
112
|
}
|
|
113
|
+
async function logoutAction() {
|
|
114
|
+
headers.cookies().set("jwt", "", {
|
|
115
|
+
...config,
|
|
116
|
+
maxAge: 0
|
|
117
|
+
});
|
|
118
|
+
navigation.redirect("/");
|
|
119
|
+
}
|
|
113
120
|
|
|
114
121
|
exports.loginUserAction = loginUserAction;
|
|
122
|
+
exports.logoutAction = logoutAction;
|
|
115
123
|
exports.registerUserAction = registerUserAction;
|
package/dist/cjs/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var FluidBackgroundV2 = require('./components/FluidBackgroundV2.js');
|
|
|
22
22
|
var RegisterForm = require('./components/forms/RegisterForm.js');
|
|
23
23
|
var SigninForm = require('./components/forms/SigninForm.js');
|
|
24
24
|
var SideNav = require('./components/dashboard/SideNav.js');
|
|
25
|
+
var LogoutButton = require('./components/LogoutButton.js');
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
|
|
@@ -41,3 +42,4 @@ exports.FluidBackground = FluidBackgroundV2.default;
|
|
|
41
42
|
exports.RegisterForm = RegisterForm.default;
|
|
42
43
|
exports.SigninForm = SigninForm.default;
|
|
43
44
|
exports.SideNav = SideNav.default;
|
|
45
|
+
exports.LogoutButton = LogoutButton.default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/*
|
|
3
|
+
* UMWD-Components
|
|
4
|
+
* @copyright Jelle Paulus
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React__default from 'react';
|
|
9
|
+
import { logoutAction } from '../data/actions/auth-actions.js';
|
|
10
|
+
import { Button } from '@mui/material';
|
|
11
|
+
import LogoutIcon from '@mui/icons-material/Logout';
|
|
12
|
+
|
|
13
|
+
//
|
|
14
|
+
function LogoutButton(_ref) {
|
|
15
|
+
let {
|
|
16
|
+
text = "Log out",
|
|
17
|
+
variant = "text"
|
|
18
|
+
} = _ref;
|
|
19
|
+
return /*#__PURE__*/React__default.createElement("form", {
|
|
20
|
+
action: logoutAction
|
|
21
|
+
}, /*#__PURE__*/React__default.createElement(Button, {
|
|
22
|
+
type: "submit"
|
|
23
|
+
// aria-disabled={status.pending || loading}
|
|
24
|
+
// disabled={status.pending || loading}
|
|
25
|
+
,
|
|
26
|
+
startIcon: /*#__PURE__*/React__default.createElement(LogoutIcon, null),
|
|
27
|
+
variant: variant
|
|
28
|
+
}, text));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { LogoutButton as default };
|
|
@@ -159,7 +159,13 @@ function SideNav(_ref) {
|
|
|
159
159
|
}
|
|
160
160
|
}, /*#__PURE__*/React.createElement(IconButton, {
|
|
161
161
|
onClick: handleDrawerClose
|
|
162
|
-
}, theme.direction === "rtl" ? /*#__PURE__*/React.createElement(ChevronRight, null) : /*#__PURE__*/React.createElement(ChevronLeft, null))), /*#__PURE__*/React.createElement(Divider, null), sections.map((section, index) => /*#__PURE__*/React.createElement(
|
|
162
|
+
}, theme.direction === "rtl" ? /*#__PURE__*/React.createElement(ChevronRight, null) : /*#__PURE__*/React.createElement(ChevronLeft, null))), /*#__PURE__*/React.createElement(Divider, null), sections.map((section, index) => /*#__PURE__*/React.createElement(Box, {
|
|
163
|
+
sx: {
|
|
164
|
+
display: "flex",
|
|
165
|
+
flexDirection: "column",
|
|
166
|
+
alignItems: "flex-start"
|
|
167
|
+
}
|
|
168
|
+
}, /*#__PURE__*/React.createElement(Link, {
|
|
163
169
|
key: index,
|
|
164
170
|
href: section.link,
|
|
165
171
|
passHref: true
|
|
@@ -171,11 +177,30 @@ function SideNav(_ref) {
|
|
|
171
177
|
p: 1,
|
|
172
178
|
cursor: "pointer"
|
|
173
179
|
}
|
|
174
|
-
}, section.icon, open && /*#__PURE__*/React.createElement(Typography, {
|
|
180
|
+
}, section.icon, !open && section.subSections && /*#__PURE__*/React.createElement(Typography, null, "..."), open && /*#__PURE__*/React.createElement(Typography, {
|
|
175
181
|
sx: {
|
|
176
182
|
pl: 2
|
|
177
183
|
}
|
|
178
|
-
}, section.title)))
|
|
184
|
+
}, section.title))), section.subSections && open && section.subSections.map((subSection, index) => {
|
|
185
|
+
return /*#__PURE__*/React.createElement(Link, {
|
|
186
|
+
key: index,
|
|
187
|
+
href: subSection.link,
|
|
188
|
+
passHref: true
|
|
189
|
+
}, /*#__PURE__*/React.createElement(Box, {
|
|
190
|
+
sx: {
|
|
191
|
+
display: "flex",
|
|
192
|
+
alignItems: "center",
|
|
193
|
+
justifyContent: "center",
|
|
194
|
+
p: 1,
|
|
195
|
+
cursor: "pointer"
|
|
196
|
+
}
|
|
197
|
+
}, /*#__PURE__*/React.createElement(Typography, {
|
|
198
|
+
variant: "body2",
|
|
199
|
+
sx: {
|
|
200
|
+
pl: 4
|
|
201
|
+
}
|
|
202
|
+
}, subSection.title)));
|
|
203
|
+
})))), /*#__PURE__*/React.createElement(Box, {
|
|
179
204
|
component: "main",
|
|
180
205
|
sx: {
|
|
181
206
|
flexGrow: 1,
|
|
@@ -108,5 +108,12 @@ async function loginUserAction(prevState, formData) {
|
|
|
108
108
|
cookies().set("jwt", responseData.jwt, config);
|
|
109
109
|
redirect("/dashboard");
|
|
110
110
|
}
|
|
111
|
+
async function logoutAction() {
|
|
112
|
+
cookies().set("jwt", "", {
|
|
113
|
+
...config,
|
|
114
|
+
maxAge: 0
|
|
115
|
+
});
|
|
116
|
+
redirect("/");
|
|
117
|
+
}
|
|
111
118
|
|
|
112
|
-
export { loginUserAction, registerUserAction };
|
|
119
|
+
export { loginUserAction, logoutAction, registerUserAction };
|
package/dist/esm/index.js
CHANGED
|
@@ -20,3 +20,4 @@ export { default as FluidBackground } from './components/FluidBackgroundV2.js';
|
|
|
20
20
|
export { default as RegisterForm } from './components/forms/RegisterForm.js';
|
|
21
21
|
export { default as SigninForm } from './components/forms/SigninForm.js';
|
|
22
22
|
export { default as SideNav } from './components/dashboard/SideNav.js';
|
|
23
|
+
export { default as LogoutButton } from './components/LogoutButton.js';
|
package/package.json
CHANGED
|
@@ -1,12 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
"use client";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { logoutAction } from "../data/actions/auth-actions.ts";
|
|
4
|
+
import { Button, Skeleton } from "@mui/material";
|
|
5
|
+
import LogoutIcon from "@mui/icons-material/Logout";
|
|
3
6
|
|
|
4
|
-
|
|
7
|
+
interface LogoutButtonProps {
|
|
8
|
+
text: string;
|
|
9
|
+
variant?: "text" | "outlined" | "contained";
|
|
10
|
+
/* loadingText: string;
|
|
11
|
+
loading?: boolean; */
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//
|
|
15
|
+
function LogoutButton({
|
|
16
|
+
text = "Log out",
|
|
17
|
+
variant = "text",
|
|
18
|
+
}: Readonly<LogoutButtonProps>) {
|
|
5
19
|
return (
|
|
6
20
|
<form action={logoutAction}>
|
|
7
|
-
<
|
|
8
|
-
|
|
9
|
-
|
|
21
|
+
<Button
|
|
22
|
+
type="submit"
|
|
23
|
+
// aria-disabled={status.pending || loading}
|
|
24
|
+
// disabled={status.pending || loading}
|
|
25
|
+
startIcon={<LogoutIcon />}
|
|
26
|
+
variant={variant}
|
|
27
|
+
>
|
|
28
|
+
{/*{status.pending || loading ? <Loader text={loadingText} /> : text}*/}
|
|
29
|
+
{text}
|
|
30
|
+
</Button>
|
|
10
31
|
</form>
|
|
11
32
|
);
|
|
12
33
|
}
|
|
34
|
+
|
|
35
|
+
/* import { useFormStatus } from "react-dom";
|
|
36
|
+
|
|
37
|
+
function Loader({ text }: { readonly text: string }) {
|
|
38
|
+
return (
|
|
39
|
+
<div className="flex items-center space-x-2">
|
|
40
|
+
<Skeleton />
|
|
41
|
+
<p>{text}</p>
|
|
42
|
+
</div>
|
|
43
|
+
);
|
|
44
|
+
} */
|
|
45
|
+
|
|
46
|
+
/* export function SubmitButton({
|
|
47
|
+
text,
|
|
48
|
+
loadingText,
|
|
49
|
+
loading,
|
|
50
|
+
}: Readonly<SubmitButtonProps>) {
|
|
51
|
+
const status = useFormStatus();
|
|
52
|
+
return (
|
|
53
|
+
<Button
|
|
54
|
+
type="submit"
|
|
55
|
+
aria-disabled={status.pending || loading}
|
|
56
|
+
disabled={status.pending || loading}
|
|
57
|
+
>
|
|
58
|
+
{status.pending || loading ? <Loader text={loadingText} /> : text}
|
|
59
|
+
</Button>
|
|
60
|
+
);
|
|
61
|
+
} */
|
|
62
|
+
|
|
63
|
+
export default LogoutButton;
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
SpeedDialAction,
|
|
15
15
|
Drawer,
|
|
16
16
|
AppBar,
|
|
17
|
+
Stack,
|
|
17
18
|
} from "@mui/material";
|
|
18
19
|
import {} from "@mui/material";
|
|
19
20
|
import {
|
|
@@ -31,6 +32,10 @@ interface SideNavProps {
|
|
|
31
32
|
title: string;
|
|
32
33
|
icon: React.ReactNode;
|
|
33
34
|
link: string;
|
|
35
|
+
subSections?: Array<{
|
|
36
|
+
title: string;
|
|
37
|
+
link: string;
|
|
38
|
+
}>;
|
|
34
39
|
}>;
|
|
35
40
|
actions: Array<{
|
|
36
41
|
icon: React.ReactNode;
|
|
@@ -216,20 +221,52 @@ function SideNav({
|
|
|
216
221
|
</Box>
|
|
217
222
|
<Divider />
|
|
218
223
|
{sections.map((section, index) => (
|
|
219
|
-
<
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
224
|
+
<Box
|
|
225
|
+
sx={{
|
|
226
|
+
display: "flex",
|
|
227
|
+
flexDirection: "column",
|
|
228
|
+
alignItems: "flex-start",
|
|
229
|
+
}}
|
|
230
|
+
>
|
|
231
|
+
<Link key={index} href={section.link} passHref>
|
|
232
|
+
<Box
|
|
233
|
+
sx={{
|
|
234
|
+
display: "flex",
|
|
235
|
+
alignItems: "center",
|
|
236
|
+
justifyContent: "center",
|
|
237
|
+
p: 1,
|
|
238
|
+
cursor: "pointer",
|
|
239
|
+
}}
|
|
240
|
+
>
|
|
241
|
+
{section.icon}
|
|
242
|
+
{!open && section.subSections && <Typography>...</Typography>}
|
|
243
|
+
{open && (
|
|
244
|
+
<Typography sx={{ pl: 2 }}>{section.title}</Typography>
|
|
245
|
+
)}
|
|
246
|
+
</Box>
|
|
247
|
+
</Link>
|
|
248
|
+
{section.subSections &&
|
|
249
|
+
open &&
|
|
250
|
+
section.subSections.map((subSection, index) => {
|
|
251
|
+
return (
|
|
252
|
+
<Link key={index} href={subSection.link} passHref>
|
|
253
|
+
<Box
|
|
254
|
+
sx={{
|
|
255
|
+
display: "flex",
|
|
256
|
+
alignItems: "center",
|
|
257
|
+
justifyContent: "center",
|
|
258
|
+
p: 1,
|
|
259
|
+
cursor: "pointer",
|
|
260
|
+
}}
|
|
261
|
+
>
|
|
262
|
+
<Typography variant={"body2"} sx={{ pl: 4 }}>
|
|
263
|
+
{subSection.title}
|
|
264
|
+
</Typography>
|
|
265
|
+
</Box>
|
|
266
|
+
</Link>
|
|
267
|
+
);
|
|
268
|
+
})}
|
|
269
|
+
</Box>
|
|
233
270
|
))}
|
|
234
271
|
</Drawer>
|
|
235
272
|
|
package/src/index.js
CHANGED
|
@@ -14,3 +14,4 @@ export { default as FluidBackground } from "./components/FluidBackgroundV2.tsx";
|
|
|
14
14
|
export { default as RegisterForm } from "./components/forms/RegisterForm.tsx";
|
|
15
15
|
export { default as SigninForm } from "./components/forms/SigninForm.tsx";
|
|
16
16
|
export { default as SideNav } from "./components/dashboard/SideNav.tsx";
|
|
17
|
+
export { default as LogoutButton } from "./components/LogoutButton.tsx";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import LogoutButton from "../components/LogoutButton.tsx";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: "UMWD/LogoutButton",
|
|
6
|
+
component: LogoutButton,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const Template = ({ ...args }) => <LogoutButton data={{ ...args }} />;
|
|
10
|
+
|
|
11
|
+
export const HelloWorld = Template.bind({});
|
|
12
|
+
|
|
13
|
+
HelloWorld.args = {
|
|
14
|
+
text: "Log-Out",
|
|
15
|
+
};
|
|
@@ -32,6 +32,16 @@ HelloWorld.args = {
|
|
|
32
32
|
title: "My Account",
|
|
33
33
|
icon: <AccountBoxIcon />,
|
|
34
34
|
link: "/account",
|
|
35
|
+
subSections: [
|
|
36
|
+
{
|
|
37
|
+
title: "Dashboard",
|
|
38
|
+
link: "/account/dashboard",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
title: "Settings",
|
|
42
|
+
link: "/account/settings",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
35
45
|
},
|
|
36
46
|
],
|
|
37
47
|
};
|