@c-rex/components 0.1.14 → 0.1.15
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
CHANGED
package/src/navbar/navbar.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { FC } from "react";
|
|
|
2
2
|
import Link from "next/link";
|
|
3
3
|
import { SignInBtn } from "./sign-in-out-btns";
|
|
4
4
|
import { getServerSession } from "next-auth";
|
|
5
|
-
import {
|
|
5
|
+
import { getClientConfigs, getServerConfigs } from "@c-rex/utils/next-cookies";
|
|
6
6
|
import { SettingsMenu } from "./settings";
|
|
7
7
|
import { UserMenu } from "./user-menu";
|
|
8
8
|
import { SearchInput } from "./search-input";
|
|
@@ -14,10 +14,12 @@ interface NavBarProps {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const NavBar: FC<NavBarProps> = async ({ title, showInput, showPkgFilter }) => {
|
|
17
|
-
const
|
|
17
|
+
const clientConfigs = await getClientConfigs();
|
|
18
|
+
const serverConfigs = await getServerConfigs();
|
|
19
|
+
|
|
18
20
|
|
|
19
21
|
let session: any;
|
|
20
|
-
if (
|
|
22
|
+
if (clientConfigs.OIDC.userEnabled) {
|
|
21
23
|
session = await getServerSession();
|
|
22
24
|
}
|
|
23
25
|
|
|
@@ -42,17 +44,17 @@ export const NavBar: FC<NavBarProps> = async ({ title, showInput, showPkgFilter
|
|
|
42
44
|
<div className="flex items-center gap-2 absolute sm:static top-4 h-14 sm:h-min right-4">
|
|
43
45
|
<SearchInput showInput={showInput} showPkgFilter={showPkgFilter} placedOn="NAVBAR" />
|
|
44
46
|
|
|
45
|
-
{
|
|
47
|
+
{clientConfigs.OIDC.userEnabled && (
|
|
46
48
|
<>
|
|
47
49
|
{session ? (
|
|
48
|
-
<UserMenu session={session} />
|
|
50
|
+
<UserMenu session={session} OIDCEndPoint={serverConfigs.OIDC.user.issuer} />
|
|
49
51
|
) : (
|
|
50
52
|
<SignInBtn />
|
|
51
53
|
)}
|
|
52
54
|
</>
|
|
53
55
|
)}
|
|
54
56
|
|
|
55
|
-
{
|
|
57
|
+
{clientConfigs.languageSwitcher.enabled && (
|
|
56
58
|
<SettingsMenu />
|
|
57
59
|
)}
|
|
58
60
|
</div>
|
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import React from "react";
|
|
3
|
+
import React, { useState } from "react";
|
|
4
4
|
import { signIn } from "next-auth/react";
|
|
5
5
|
import { Button } from "@c-rex/ui/button";
|
|
6
6
|
import { useTranslations } from "next-intl";
|
|
7
7
|
|
|
8
8
|
export const SignInBtn = () => {
|
|
9
9
|
const t = useTranslations("user")
|
|
10
|
+
const [isLoading, setIsLoading] = useState<boolean>(false)
|
|
11
|
+
|
|
12
|
+
const handleSignIn = () => {
|
|
13
|
+
setIsLoading(true);
|
|
14
|
+
signIn("crex", { prompt: "login", callbackUrl: "/" });
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
return (
|
|
11
18
|
<Button
|
|
12
19
|
className="gap-2 px-5 md:flex"
|
|
13
20
|
variant="default"
|
|
14
21
|
size="sm"
|
|
15
22
|
rounded="full"
|
|
16
|
-
|
|
23
|
+
disabled={isLoading}
|
|
24
|
+
onClick={handleSignIn}
|
|
17
25
|
>
|
|
18
|
-
|
|
26
|
+
{isLoading ? (
|
|
27
|
+
<div className="flex items-center justify-center py-4">
|
|
28
|
+
<div className="animate-spin rounded-full h-5 w-5 border-2 border-gray-300 border-t-gray-950" />
|
|
29
|
+
</div>
|
|
30
|
+
) : (
|
|
31
|
+
<span>{t("signIn")}</span>
|
|
32
|
+
)}
|
|
19
33
|
</Button>
|
|
20
34
|
);
|
|
21
35
|
}
|
package/src/navbar/user-menu.tsx
CHANGED
|
@@ -11,19 +11,17 @@ import {
|
|
|
11
11
|
} from "@c-rex/ui/dropdown-menu"
|
|
12
12
|
import { CircleUser } from "lucide-react";
|
|
13
13
|
import { useTranslations } from "next-intl";
|
|
14
|
-
import { useAppConfig } from "@c-rex/contexts/config-provider";
|
|
15
14
|
import { signOut } from "next-auth/react";
|
|
16
15
|
|
|
17
16
|
|
|
18
17
|
interface Props {
|
|
19
18
|
session: any
|
|
19
|
+
OIDCEndPoint: string
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export const UserMenu: FC<Props> = ({ session }) => {
|
|
23
|
-
const t = useTranslations();
|
|
24
|
-
const { configs } = useAppConfig();
|
|
25
22
|
|
|
26
|
-
|
|
23
|
+
export const UserMenu: FC<Props> = ({ session, OIDCEndPoint }) => {
|
|
24
|
+
const t = useTranslations();
|
|
27
25
|
|
|
28
26
|
return (
|
|
29
27
|
<DropdownMenu>
|
|
@@ -38,18 +36,21 @@ export const UserMenu: FC<Props> = ({ session }) => {
|
|
|
38
36
|
<DropdownMenuSeparator />
|
|
39
37
|
<DropdownMenuGroup>
|
|
40
38
|
<DropdownMenuItem>
|
|
41
|
-
<a href={`${
|
|
39
|
+
<a href={`${OIDCEndPoint}oidc/Profile`} target="_blank" rel="noreferrer">
|
|
42
40
|
Profile settings
|
|
43
41
|
</a>
|
|
44
42
|
</DropdownMenuItem>
|
|
45
43
|
|
|
46
44
|
<DropdownMenuItem>
|
|
47
|
-
<a href={`${
|
|
45
|
+
<a href={`${OIDCEndPoint}oidc/Profile/ChangePassword`} target="_blank" rel="noreferrer">
|
|
48
46
|
Change password
|
|
49
47
|
</a>
|
|
50
48
|
</DropdownMenuItem>
|
|
51
49
|
|
|
52
|
-
<DropdownMenuItem
|
|
50
|
+
<DropdownMenuItem
|
|
51
|
+
onClick={() => signOut({ callbackUrl: "/api/auth/logout" })}
|
|
52
|
+
className='text-red-500 focus:text-red-500'
|
|
53
|
+
>
|
|
53
54
|
{t("user.signOut")}
|
|
54
55
|
</DropdownMenuItem>
|
|
55
56
|
</DropdownMenuGroup>
|