mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Merge pull request #296 from akhilmhdh/fix/ws-redirect
feat(ui): removed workspace context redirect and added redirect when ws is deleted
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { createContext, ReactNode, useContext, useEffect, useMemo } from 'react';
|
import { createContext, ReactNode, useContext, useMemo } from 'react';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
|
|
||||||
import { useGetUserWorkspaces } from '@app/hooks/api';
|
import { useGetUserWorkspaces } from '@app/hooks/api';
|
||||||
@@ -30,15 +30,6 @@ export const WorkspaceProvider = ({ children }: Props): JSX.Element => {
|
|||||||
};
|
};
|
||||||
}, [ws, workspaceId, isLoading]);
|
}, [ws, workspaceId, isLoading]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// not loading and current workspace is empty
|
|
||||||
// ws empty means user has no access to the ws
|
|
||||||
// push to the first workspace
|
|
||||||
if (!isLoading && !value?.currentWorkspace?._id) {
|
|
||||||
router.push(`/dashboard/${value.workspaces?.[0]?._id}`);
|
|
||||||
}
|
|
||||||
}, [value?.currentWorkspace?._id, isLoading, value.workspaces?.[0]?._id, router.pathname]);
|
|
||||||
|
|
||||||
return <WorkspaceContext.Provider value={value}>{children}</WorkspaceContext.Provider>;
|
return <WorkspaceContext.Provider value={value}>{children}</WorkspaceContext.Provider>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import crypto from 'crypto';
|
|||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useRouter } from 'next/router';
|
||||||
|
|
||||||
import { useNotificationContext } from '@app/components/context/Notifications/NotificationProvider';
|
import { useNotificationContext } from '@app/components/context/Notifications/NotificationProvider';
|
||||||
import NavHeader from '@app/components/navigation/NavHeader';
|
import NavHeader from '@app/components/navigation/NavHeader';
|
||||||
@@ -37,7 +38,8 @@ import {
|
|||||||
|
|
||||||
export const ProjectSettingsPage = () => {
|
export const ProjectSettingsPage = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { currentWorkspace } = useWorkspace();
|
const { currentWorkspace, workspaces } = useWorkspace();
|
||||||
|
const router = useRouter();
|
||||||
const { data: serviceTokens } = useGetUserWsServiceTokens({
|
const { data: serviceTokens } = useGetUserWsServiceTokens({
|
||||||
workspaceID: currentWorkspace?._id || ''
|
workspaceID: currentWorkspace?._id || ''
|
||||||
});
|
});
|
||||||
@@ -64,7 +66,6 @@ export const ProjectSettingsPage = () => {
|
|||||||
const host = window.location.origin;
|
const host = window.location.origin;
|
||||||
const isEnvServiceAllowed =
|
const isEnvServiceAllowed =
|
||||||
subscriptionPlan !== plans.starter || host !== 'https://app.infisical.com';
|
subscriptionPlan !== plans.starter || host !== 'https://app.infisical.com';
|
||||||
|
|
||||||
|
|
||||||
const onRenameWorkspace = async (name: string) => {
|
const onRenameWorkspace = async (name: string) => {
|
||||||
try {
|
try {
|
||||||
@@ -86,6 +87,9 @@ export const ProjectSettingsPage = () => {
|
|||||||
setIsDeleting.on();
|
setIsDeleting.on();
|
||||||
try {
|
try {
|
||||||
await deleteWorkspace.mutateAsync({ workspaceID });
|
await deleteWorkspace.mutateAsync({ workspaceID });
|
||||||
|
// redirect user to first workspace user is part of
|
||||||
|
const ws = workspaces.find(({ _id }) => _id !== workspaceID);
|
||||||
|
router.push(`/dashboard/${ws?._id}`);
|
||||||
createNotification({
|
createNotification({
|
||||||
text: 'Successfully deleted workspace',
|
text: 'Successfully deleted workspace',
|
||||||
type: 'success'
|
type: 'success'
|
||||||
|
|||||||
Reference in New Issue
Block a user