Skip to content

Commit 2b70262

Browse files
authored
fix: update the create ecosystem leads functionality based on ecosystem status (#8)
* fix/changes suggested for ui Signed-off-by: sujitaw <sujit.sutar@ayanworks.com> * fix/avoid other users from accessing platform admin Signed-off-by: sujitaw <sujit.sutar@ayanworks.com> --------- Signed-off-by: sujitaw <sujit.sutar@ayanworks.com>
1 parent 946ccf5 commit 2b70262

8 files changed

Lines changed: 80 additions & 34 deletions

File tree

src/app/dashboard/Dashboard.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
'use client'
2-
import { useEffect, useState, type ReactElement } from "react"
2+
import { useEffect, useState } from "react"
33

4-
import { Globe, Mail, Building2, Trash2 } from "lucide-react";
4+
import { Globe, Mail, Building2 } from "lucide-react";
55
import { Card, CardContent } from "@/components/ui/card";
66
import { getRequest } from "@/config/apiCalls";
7-
import { dashboardData } from "@/config/constant";
7+
import { dashboardData, ecosystemStatus } from "@/config/constant";
8+
import { useDispatch } from "react-redux";
9+
import { setEcosystemEnableStatus } from "@/lib/ecosystemSlice";
810

911

1012
export default function Dashboard() {
@@ -19,20 +21,38 @@ export default function Dashboard() {
1921
{ title: "Invitations Sent", value: cardData.invitations, icon: Mail },
2022
{ title: "Active Organizations", value: cardData.activeOrgs, icon: Building2 }
2123
];
24+
25+
const dispatch = useDispatch()
26+
2227
async function fetchDashboardDetails(): Promise<void> {
2328
try{
2429
const data = await getRequest(dashboardData)
25-
console.log("data",data)
2630
if (data?.data.data) {
2731
setCardData(data?.data.data)
2832
}
2933
} catch {
30-
console.log('failed to fetch dashboard details')
34+
console.error('failed to fetch dashboard details')
35+
}
36+
}
37+
38+
39+
const fetchEcosystemStatus = async ():Promise<void>=>{
40+
try{
41+
const response = await getRequest(ecosystemStatus)
42+
if (response) {
43+
dispatch(setEcosystemEnableStatus(response.data.data))
44+
}
45+
}catch(error){
46+
console.error("failed to fetch ecosystem status",error)
3147
}
3248
}
3349

50+
useEffect(()=> {
51+
},[])
52+
3453
useEffect(()=> {
3554
fetchDashboardDetails()
55+
fetchEcosystemStatus()
3656
},[])
3757

3858
return (
@@ -45,7 +65,7 @@ export default function Dashboard() {
4565
</div>
4666

4767
<div className="flex sm:flex justify-between gap-6">
48-
{stats.map(({ title, value, icon: Icon }, index) => (
68+
{stats.map(({ title, value, icon: Icon }) => (
4969
<Card
5070
key={title}
5171
className="shadow grow"

src/app/ecosystems/InvitationsList.tsx

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import React, { useEffect, useState } from "react";
1414
import { dateConversion } from "@/config/common.functions";
1515
import {
1616
invitationsApi,
17-
signOutApi,
1817
} from "@/config/constant";
1918
import { getRequest, postRequest } from "@/config/apiCalls";
2019

@@ -23,15 +22,13 @@ import { CellContext } from "@tanstack/react-table";
2322
import { DataTable } from "@/components/ui/generic-table-component/data-table";
2423
import Modal from "@/components/Modal";
2524
import { RefreshCw } from "lucide-react";
26-
import { signOut } from "next-auth/react";
27-
import { useAppSelector } from "@/lib/hooks";
28-
import { useRouter } from "next/navigation";
2925
import { Input } from "@/components/ui/input";
30-
import Alert from "@/components/alert";
3126
import { HttpStatusCode } from "axios";
3227
import { AlertComponent } from "@/components/AlertComponent";
3328
import { TooltipContent, TooltipProvider, TooltipTrigger, Tooltip } from "@/components/ui/tooltip";
3429
import { Formik, Form as FormikForm } from "formik";
30+
import { useAppSelector } from '@/lib/hooks';
31+
import { RootState } from '@/lib/store';
3532

3633

3734

@@ -70,12 +67,8 @@ const InvitationsList = (): React.JSX.Element => {
7067
const [errorMessage, setErrorMessage] = useState("");
7168
const [showAlert, setShowAlert] = useState(false);
7269
const [message, setMessage] = useState('')
73-
const sessionId = useAppSelector((state) => state.session.sessionId);
7470

75-
76-
const accessToken = useAppSelector(
77-
(state) => state.session.token
78-
);
71+
const ecosystemEnabled = useAppSelector((state: RootState) => state.ecosystem?.ecosystemEnableStatus)
7972

8073
const [paginationParameter, setPaginationParameter] = useState<PageParameter>(
8174
{
@@ -93,7 +86,6 @@ const InvitationsList = (): React.JSX.Element => {
9386
}
9487
);
9588

96-
const redirectUrl = `${process.env.NEXT_PUBLIC_CLIENT_URL}/dashboard`;
9789

9890
const validationSchema = Yup.object().shape({
9991
email: Yup.string()
@@ -301,13 +293,15 @@ const InvitationsList = (): React.JSX.Element => {
301293
className={`h-5 w-5 ${tableLoading ? "animate-spin" : ""}`}
302294
/>
303295
</Button>
304-
<Button
305-
onClick={showInvitationPopUp}
306-
className="flex items-center gap-2 px-4 py-2 text-base font-medium"
307-
disabled={loading}
308-
>
309-
Create Ecosystem Lead
310-
</Button>
296+
{ ecosystemEnabled &&
297+
<Button
298+
onClick={showInvitationPopUp}
299+
className="flex items-center gap-2 px-4 py-2 text-base font-medium"
300+
disabled={loading}
301+
>
302+
Create Ecosystem Lead
303+
</Button>
304+
}
311305
</div>
312306
</div>
313307
<div className="relative min-h-[400px]">

src/app/sessions/Sessions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function Sessions(): JSX.Element {
2525
const [deletionId, setDeletionId] = useState<string | null>(null)
2626

2727
const [showConfirmation, setShowConfirmation] = useState<boolean>(false)
28-
const userId = useAppSelector((state: RootState) =>{console.log("state",state);return state.user?.userDetails?.userId})
28+
const userId = useAppSelector((state: RootState) =>{return state.user?.userDetails?.userId})
2929
console.log("userId",userId)
3030
const currentSession = useAppSelector(
3131
(state: RootState) => state.session.sessionId,

src/app/settings/Settings.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@ import { Globe, CheckCircle2, XCircle } from "lucide-react";
88
import { getRequest, putRequest } from "@/config/apiCalls";
99
import { ecosystemStatus, updateEcosystemStatusApi } from "@/config/constant";
1010
import { HttpStatusCode } from "axios";
11+
import { useAppSelector } from "@/lib/hooks";
12+
import { RootState } from "@/lib/store";
13+
import { useDispatch } from "react-redux";
14+
import { setEcosystemEnableStatus } from "@/lib/ecosystemSlice";
1115

1216
const Settings = () => {
13-
const [ecosystemEnabled, setEcosystemEnabled] = useState(true);
1417
const [alertMessage, setAlertMessage] = useState<string | null>(null);
1518
const [alertType, setAlertType] = useState<"success" | "error">("success");
19+
const ecosystemEnabled = useAppSelector((state: RootState) => state.ecosystem?.ecosystemEnableStatus)
20+
21+
const dispatch = useDispatch()
1622

1723
async function updateEcosystemStatus(checked: boolean):Promise<void>{
1824
try{
1925
const response = await putRequest(updateEcosystemStatusApi,{ isEcosystemEnabled: checked })
20-
console.log("response",response)
2126
if (response && response.status === HttpStatusCode.Ok) {
22-
setEcosystemEnabled(checked);
27+
dispatch(setEcosystemEnableStatus(checked))
2328
setAlertType("success");
2429
setAlertMessage(`Ecosystem ${checked ? "enabled" : "disabled"} successfully`);
2530
setTimeout(() => setAlertMessage(null), 3000);
@@ -38,9 +43,9 @@ const Settings = () => {
3843
const fetchEcosystemStatus = async ():Promise<void>=>{
3944
try{
4045
const response = await getRequest(ecosystemStatus)
41-
console.log("response",response)
4246
if (response) {
43-
setEcosystemEnabled(response.data.data)
47+
dispatch(setEcosystemEnableStatus(response.data.data))
48+
setAlertType("success");
4449
}
4550
}catch(error){
4651
console.error("failed to fetch ecosystem status",error)
@@ -49,6 +54,7 @@ const Settings = () => {
4954

5055
useEffect(()=> {
5156
fetchEcosystemStatus()
57+
5258
},[])
5359

5460
return (

src/components/SessionCheck.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { setRefreshToken, setSessionId, setSessionToken } from '@/lib/sessionSli
55
import { signOut, useSession } from 'next-auth/react'
66
import { useAppDispatch, useAppSelector } from '@/lib/hooks'
77
import { useEffect, useState } from 'react'
8-
import { usePathname, useRouter } from 'next/navigation'
8+
import { useRouter } from 'next/navigation'
99

1010
import Image from 'next/image'
1111
import Loader from '@/components/Loader'
@@ -21,7 +21,6 @@ const SessionCheck = ({
2121
const [isChecking, setIsChecking] = useState(true)
2222
const dispatch = useAppDispatch()
2323
const router = useRouter()
24-
const pathname = usePathname()
2524
const token = useAppSelector((state) => state.session.token);
2625

2726
const setSessionDetails = (sessionDetails: any): void => {

src/config/apiCalls.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ axios.interceptors.request.use(
112112
const handleError = async (error: any): Promise<never> => {
113113
if (error.response) {
114114
// Server responded with a status other than 200 range
115+
if (error.response.status === 403){
116+
logoutUser()
117+
}
115118
if (error.response.status === 401) {
116119
await generateAccessToken()
117120
}

src/lib/ecosystemSlice.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { PayloadAction, createSlice } from "@reduxjs/toolkit";
2+
3+
interface Ecosystem {
4+
ecosystemEnableStatus: boolean
5+
}
6+
7+
const initialState: Ecosystem = {
8+
ecosystemEnableStatus: false,
9+
};
10+
11+
const ecosystemSlice = createSlice({
12+
name: "ecosystem",
13+
initialState,
14+
reducers: {
15+
setEcosystemEnableStatus: (state, action: PayloadAction<boolean>) => {
16+
state.ecosystemEnableStatus = action.payload;
17+
},
18+
},
19+
});
20+
21+
export const { setEcosystemEnableStatus } = ecosystemSlice.actions;
22+
export default ecosystemSlice.reducer;

src/lib/store.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ import storage from "redux-persist/lib/storage";
66
import userReducer from "./userSlice";
77
import userRegistrationSlice from "./userRegistrationSlice";
88
import sessionSlice from "./sessionSlice";
9+
import ecosystemSlice from "./ecosystemSlice";
910

1011
const rootReducer = combineReducers({
1112
session: sessionSlice,
1213
organization: organizationReducer,
1314
user: userReducer,
14-
userRegistartion: userRegistrationSlice
15+
userRegistartion: userRegistrationSlice,
16+
ecosystem: ecosystemSlice
1517
});
1618

1719
const persistConfig = {
1820
key: "root",
1921
storage,
20-
whitelist: ["session", "organization", "user", "userRegistartion"],
22+
whitelist: ["session", "organization", "user", "userRegistartion", "ecosystem"],
2123
};
2224

2325
const persistedReducer = persistReducer(persistConfig, rootReducer);

0 commit comments

Comments
 (0)