feat: Create login page for admin.
wip: Admin user Configuration
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
Group,
|
||||
Radio,
|
||||
Text,
|
||||
PasswordInput,
|
||||
} from '@mantine/core';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
|
||||
@@ -339,9 +340,9 @@ const AddBeneficiaryOthers: React.FC = () => {
|
||||
// disabled={isVisibilityLocked}
|
||||
readOnly={isVisibilityLocked}
|
||||
required
|
||||
// onCopy={(e) => e.preventDefault()}
|
||||
// onPaste={(e) => e.preventDefault()}
|
||||
// onCut={(e) => e.preventDefault()}
|
||||
onCopy={(e) => e.preventDefault()}
|
||||
onPaste={(e) => e.preventDefault()}
|
||||
onCut={(e) => e.preventDefault()}
|
||||
/>
|
||||
|
||||
{validationStatus === "error" && (
|
||||
@@ -380,7 +381,7 @@ const AddBeneficiaryOthers: React.FC = () => {
|
||||
{otpSent && (
|
||||
<>
|
||||
<Grid.Col span={3}>
|
||||
<TextInput
|
||||
<PasswordInput
|
||||
label="Enter OTP"
|
||||
placeholder="Enter OTP"
|
||||
value={otp}
|
||||
|
@@ -11,6 +11,7 @@ import {
|
||||
Group,
|
||||
Radio,
|
||||
Text,
|
||||
PasswordInput,
|
||||
} from '@mantine/core';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import AddBeneficiaryOthers from './addBeneficiaryOthers';
|
||||
@@ -253,9 +254,9 @@ const AddBeneficiary: React.FC = () => {
|
||||
// disabled={isVisibilityLocked}
|
||||
readOnly={isVisibilityLocked}
|
||||
required
|
||||
// onCopy={(e) => e.preventDefault()}
|
||||
// onPaste={(e) => e.preventDefault()}
|
||||
// onCut={(e) => e.preventDefault()}
|
||||
onCopy={(e) => e.preventDefault()}
|
||||
onPaste={(e) => e.preventDefault()}
|
||||
onCut={(e) => e.preventDefault()}
|
||||
/>
|
||||
|
||||
{validationStatus === "error" && (
|
||||
@@ -294,7 +295,7 @@ const AddBeneficiary: React.FC = () => {
|
||||
{otpSent && (
|
||||
<>
|
||||
<Grid.Col span={3}>
|
||||
<TextInput
|
||||
<PasswordInput
|
||||
label="Enter OTP"
|
||||
placeholder="Enter OTP"
|
||||
value={otp}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import { Button, Group, Modal, Paper, Radio, ScrollArea, Select, Stack, Text, TextInput, Title } from "@mantine/core";
|
||||
import { Button, Group, Modal, Paper, PasswordInput, Radio, ScrollArea, Select, Stack, Text, TextInput, Title } from "@mantine/core";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { generateOTP } from '@/app/OTPGenerator';
|
||||
@@ -361,9 +361,9 @@ export default function QuickPay() {
|
||||
setConfirmBeneficiaryAcc(value);
|
||||
}
|
||||
}}
|
||||
// onCopy={(e) => e.preventDefault()}
|
||||
// onPaste={(e) => e.preventDefault()}
|
||||
// onCut={(e) => e.preventDefault()}
|
||||
onCopy={(e) => e.preventDefault()}
|
||||
onPaste={(e) => e.preventDefault()}
|
||||
onCut={(e) => e.preventDefault()}
|
||||
withAsterisk
|
||||
readOnly={isVisibilityLocked}
|
||||
/>
|
||||
@@ -418,7 +418,7 @@ export default function QuickPay() {
|
||||
</Group>
|
||||
<Group grow>
|
||||
{showOtpField && (
|
||||
<TextInput
|
||||
<PasswordInput
|
||||
label="OTP"
|
||||
placeholder="Enter OTP"
|
||||
type="otp"
|
||||
|
@@ -14,12 +14,44 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
const pathname = usePathname();
|
||||
const [authorized, SetAuthorized] = useState<boolean | null>(null);
|
||||
const [userLastLoginDetails, setUserLastLoginDetails] = useState(null);
|
||||
const [custname, setCustname] = useState<string | null>(null);
|
||||
|
||||
async function handleLogout(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
localStorage.removeItem("access_token");
|
||||
router.push("/login");
|
||||
}
|
||||
|
||||
async function handleFetchUserName() {
|
||||
try {
|
||||
const token = localStorage.getItem("access_token");
|
||||
const response = await fetch('api/customer', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': `Bearer ${token}`
|
||||
},
|
||||
});
|
||||
const data = await response.json();
|
||||
if (response.ok && Array.isArray(data)) {
|
||||
if (data.length > 0) {
|
||||
const name = data[0].custname;
|
||||
setCustname(name);
|
||||
}
|
||||
} else {
|
||||
throw new Error();
|
||||
}
|
||||
} catch {
|
||||
notifications.show({
|
||||
withBorder: true,
|
||||
color: "red",
|
||||
title: "Please try again later",
|
||||
message: "Unable to Fetch, Please try again later",
|
||||
autoClose: 5000,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const token = localStorage.getItem("access_token");
|
||||
if (!token) {
|
||||
@@ -28,6 +60,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
}
|
||||
else {
|
||||
SetAuthorized(true);
|
||||
handleFetchUserName();
|
||||
}
|
||||
}, []);
|
||||
|
||||
@@ -44,8 +77,8 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
const data = await response.json();
|
||||
if (response.ok) {
|
||||
return data;
|
||||
}
|
||||
else if(response.status ===401 ||data.message === 'invalid or expired token'){
|
||||
}
|
||||
else if (response.status === 401 || data.message === 'invalid or expired token') {
|
||||
// console.log(data);
|
||||
localStorage.removeItem("access_token");
|
||||
router.push('/login');
|
||||
@@ -125,7 +158,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
>
|
||||
<Stack gap={0} align="flex-start">
|
||||
<Title order={4} style={{ fontFamily: "inter", fontSize: '22px' }}>
|
||||
Welcome, Rajat Kumar Maharana
|
||||
Welcome, {custname ?? null}
|
||||
</Title>
|
||||
<Text size="xs" c="gray" style={{ fontFamily: "inter", fontSize: '13px' }}>
|
||||
Last logged in at {userLastLoginDetails ? new Date(userLastLoginDetails).toLocaleString() : "N/A"}
|
||||
|
Reference in New Issue
Block a user