mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-24 11:39:22 -05:00
fix: org leaving issue and minor tweaks (#4691)
This commit is contained in:
committed by
GitHub
parent
f7f5737abf
commit
9b3d409695
+1
-1
@@ -127,7 +127,7 @@ export const LandingSidebar = ({
|
||||
await signOut({ callbackUrl: "/auth/login" });
|
||||
await formbricksLogout();
|
||||
}}
|
||||
icon={<LogOutIcon className="h-4 w-4" strokeWidth={1.5} />}>
|
||||
icon={<LogOutIcon className="mr-2 h-4 w-4" strokeWidth={1.5} />}>
|
||||
{t("common.logout")}
|
||||
</DropdownMenuItem>
|
||||
|
||||
|
||||
@@ -392,7 +392,7 @@ export const MainNavigation = ({
|
||||
router.push(route.url);
|
||||
await formbricksLogout();
|
||||
}}
|
||||
icon={<LogOutIcon className="h-4 w-4" strokeWidth={1.5} />}>
|
||||
icon={<LogOutIcon className="mr-2 h-4 w-4" strokeWidth={1.5} />}>
|
||||
{t("common.logout")}
|
||||
</DropdownMenuItem>
|
||||
|
||||
|
||||
+2
@@ -11,6 +11,7 @@ import { useTranslations } from "next-intl";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import toast from "react-hot-toast";
|
||||
import { FORMBRICKS_ENVIRONMENT_ID_LS } from "@formbricks/lib/localStorage";
|
||||
import { TInvitee } from "@formbricks/types/invites";
|
||||
import { TOrganizationRole } from "@formbricks/types/memberships";
|
||||
import { TOrganization } from "@formbricks/types/organizations";
|
||||
@@ -53,6 +54,7 @@ export const OrganizationActions = ({
|
||||
toast.success(t("environments.settings.general.member_deleted_successfully"));
|
||||
router.refresh();
|
||||
setLoading(false);
|
||||
localStorage.removeItem(FORMBRICKS_ENVIRONMENT_ID_LS);
|
||||
router.push("/");
|
||||
} catch (err) {
|
||||
toast.error(`Error: ${err.message}`);
|
||||
|
||||
@@ -16,13 +16,15 @@ import { TProject } from "@formbricks/types/project";
|
||||
interface DeleteProjectRenderProps {
|
||||
isDeleteDisabled: boolean;
|
||||
isOwnerOrManager: boolean;
|
||||
project: TProject;
|
||||
currentProject: TProject;
|
||||
organizationProjects: TProject[];
|
||||
}
|
||||
|
||||
export const DeleteProjectRender = ({
|
||||
isDeleteDisabled,
|
||||
isOwnerOrManager,
|
||||
project,
|
||||
currentProject,
|
||||
organizationProjects,
|
||||
}: DeleteProjectRenderProps) => {
|
||||
const t = useTranslations();
|
||||
const router = useRouter();
|
||||
@@ -30,9 +32,20 @@ export const DeleteProjectRender = ({
|
||||
const [isDeleting, setIsDeleting] = useState(false);
|
||||
const handleDeleteProject = async () => {
|
||||
setIsDeleting(true);
|
||||
const deleteProjectResponse = await deleteProjectAction({ projectId: project.id });
|
||||
const deleteProjectResponse = await deleteProjectAction({ projectId: currentProject.id });
|
||||
if (deleteProjectResponse?.data) {
|
||||
localStorage.removeItem(FORMBRICKS_ENVIRONMENT_ID_LS);
|
||||
if (organizationProjects.length === 1) {
|
||||
localStorage.removeItem(FORMBRICKS_ENVIRONMENT_ID_LS);
|
||||
} else if (organizationProjects.length > 1) {
|
||||
// prevents changing of organization when deleting project
|
||||
const remainingProjects = organizationProjects.filter((project) => project.id !== currentProject.id);
|
||||
const productionEnvironment = remainingProjects[0].environments.find(
|
||||
(environment) => environment.type === "production"
|
||||
);
|
||||
if (productionEnvironment) {
|
||||
localStorage.setItem(FORMBRICKS_ENVIRONMENT_ID_LS, productionEnvironment.id);
|
||||
}
|
||||
}
|
||||
toast.success(t("environments.project.general.project_deleted_successfully"));
|
||||
router.push("/");
|
||||
} else {
|
||||
@@ -51,7 +64,7 @@ export const DeleteProjectRender = ({
|
||||
{t(
|
||||
"environments.project.general.delete_project_name_includes_surveys_responses_people_and_more",
|
||||
{
|
||||
projectName: truncate(project.name, 30),
|
||||
projectName: truncate(currentProject.name, 30),
|
||||
}
|
||||
)}{" "}
|
||||
<strong>{t("environments.project.general.this_action_cannot_be_undone")}</strong>
|
||||
@@ -81,7 +94,7 @@ export const DeleteProjectRender = ({
|
||||
setOpen={setIsDeleteDialogOpen}
|
||||
onDelete={handleDeleteProject}
|
||||
text={t("environments.project.general.delete_project_confirmation", {
|
||||
projectName: truncate(project.name, 30),
|
||||
projectName: truncate(currentProject.name, 30),
|
||||
})}
|
||||
isDeleting={isDeleting}
|
||||
/>
|
||||
|
||||
@@ -8,11 +8,17 @@ import { TProject } from "@formbricks/types/project";
|
||||
|
||||
interface DeleteProjectProps {
|
||||
environmentId: string;
|
||||
project: TProject;
|
||||
currentProject: TProject;
|
||||
organizationProjects: TProject[];
|
||||
isOwnerOrManager: boolean;
|
||||
}
|
||||
|
||||
export const DeleteProject = async ({ environmentId, project, isOwnerOrManager }: DeleteProjectProps) => {
|
||||
export const DeleteProject = async ({
|
||||
environmentId,
|
||||
currentProject,
|
||||
organizationProjects,
|
||||
isOwnerOrManager,
|
||||
}: DeleteProjectProps) => {
|
||||
const t = await getTranslations();
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session) {
|
||||
@@ -31,7 +37,8 @@ export const DeleteProject = async ({ environmentId, project, isOwnerOrManager }
|
||||
<DeleteProjectRender
|
||||
isDeleteDisabled={isDeleteDisabled}
|
||||
isOwnerOrManager={isOwnerOrManager}
|
||||
project={project}
|
||||
currentProject={currentProject}
|
||||
organizationProjects={organizationProjects}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ import { IS_FORMBRICKS_CLOUD } from "@formbricks/lib/constants";
|
||||
import { getMembershipByUserIdOrganizationId } from "@formbricks/lib/membership/service";
|
||||
import { getAccessFlags } from "@formbricks/lib/membership/utils";
|
||||
import { getOrganizationByEnvironmentId } from "@formbricks/lib/organization/service";
|
||||
import { getProjectByEnvironmentId } from "@formbricks/lib/project/service";
|
||||
import { getProjectByEnvironmentId, getProjects } from "@formbricks/lib/project/service";
|
||||
import { DeleteProject } from "./components/delete-project";
|
||||
import { EditProjectNameForm } from "./components/edit-project-name-form";
|
||||
import { EditWaitingTimeForm } from "./components/edit-waiting-time-form";
|
||||
@@ -41,6 +41,8 @@ export const GeneralSettingsPage = async (props: { params: Promise<{ environment
|
||||
throw new Error(t("common.organization_not_found"));
|
||||
}
|
||||
|
||||
const organizationProjects = await getProjects(organization.id);
|
||||
|
||||
const currentUserMembership = await getMembershipByUserIdOrganizationId(session?.user.id, organization.id);
|
||||
const projectPermission = await getProjectPermissionByUserId(session.user.id, project.id);
|
||||
|
||||
@@ -79,7 +81,8 @@ export const GeneralSettingsPage = async (props: { params: Promise<{ environment
|
||||
description={t("environments.project.general.delete_project_settings_description")}>
|
||||
<DeleteProject
|
||||
environmentId={params.environmentId}
|
||||
project={project}
|
||||
currentProject={project}
|
||||
organizationProjects={organizationProjects}
|
||||
isOwnerOrManager={isOwnerOrManager}
|
||||
/>
|
||||
</SettingsCard>
|
||||
|
||||
Reference in New Issue
Block a user