umwd-components 0.1.232 → 0.1.233
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/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/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/index.js +1 -0
- package/src/stories/LogoutButton.stories.js +15 -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;
|
|
@@ -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 };
|
|
@@ -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;
|
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
|
+
};
|