-
Notifications
You must be signed in to change notification settings - Fork 964
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1150 from akhilmhdh/fix/mrg-bug-fixes
fix: resolved error in org settings and integrations page alert hidde…
- Loading branch information
Showing
9 changed files
with
89 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 58 additions & 69 deletions
127
frontend/src/views/Settings/OrgSettingsPage/components/OrgDeleteSection/OrgDeleteSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,70 @@ | ||
import { useRouter } from "next/router"; | ||
|
||
import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider"; | ||
import { | ||
Button, | ||
DeleteActionModal | ||
} from "@app/components/v2"; | ||
import { useOrganization, useUser } from "@app/context"; | ||
import { | ||
useDeleteOrgById, | ||
useGetOrgUsers | ||
} from "@app/hooks/api"; | ||
import { Button, DeleteActionModal } from "@app/components/v2"; | ||
import { useOrganization, useOrgPermission } from "@app/context"; | ||
import { useDeleteOrgById } from "@app/hooks/api"; | ||
import { usePopUp } from "@app/hooks/usePopUp"; | ||
import { navigateUserToOrg } from "@app/views/Login/Login.utils"; | ||
|
||
export const OrgDeleteSection = () => { | ||
const router = useRouter(); | ||
const { currentOrg } = useOrganization(); | ||
const { user } = useUser(); | ||
const { createNotification } = useNotificationContext(); | ||
const { data: members } = useGetOrgUsers(currentOrg?._id ?? ""); | ||
|
||
const membershipOrg = members?.find((member) => member.user._id === user._id); | ||
const router = useRouter(); | ||
const { currentOrg } = useOrganization(); | ||
const { createNotification } = useNotificationContext(); | ||
const { membership } = useOrgPermission(); | ||
|
||
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ | ||
"deleteOrg" | ||
] as const); | ||
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ | ||
"deleteOrg" | ||
] as const); | ||
|
||
const { mutateAsync, isLoading } = useDeleteOrgById(); | ||
|
||
const handleDeleteOrgSubmit = async () => { | ||
try { | ||
if (!currentOrg?._id) return; | ||
|
||
await mutateAsync({ | ||
organizationId: currentOrg?._id | ||
}); | ||
|
||
createNotification({ | ||
text: "Successfully deleted organization", | ||
type: "success" | ||
}); | ||
const { mutateAsync, isLoading } = useDeleteOrgById(); | ||
|
||
await navigateUserToOrg(router); | ||
|
||
handlePopUpClose("deleteOrg"); | ||
} catch (err) { | ||
console.error(err); | ||
createNotification({ | ||
text: "Failed to delete organization", | ||
type: "error" | ||
}); | ||
} | ||
const handleDeleteOrgSubmit = async () => { | ||
try { | ||
if (!currentOrg?._id) return; | ||
|
||
await mutateAsync({ | ||
organizationId: currentOrg?._id | ||
}); | ||
|
||
createNotification({ | ||
text: "Successfully deleted organization", | ||
type: "success" | ||
}); | ||
|
||
await navigateUserToOrg(router); | ||
|
||
handlePopUpClose("deleteOrg"); | ||
} catch (err) { | ||
console.error(err); | ||
createNotification({ | ||
text: "Failed to delete organization", | ||
type: "error" | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="p-4 bg-mineshaft-900 rounded-lg border border-mineshaft-600 mb-6"> | ||
<p className="text-xl font-semibold text-mineshaft-100 mb-4"> | ||
Danger Zone | ||
</p> | ||
<Button | ||
isLoading={isLoading} | ||
colorSchema="danger" | ||
variant="outline_bg" | ||
type="submit" | ||
onClick={() => handlePopUpOpen("deleteOrg")} | ||
isDisabled={(membershipOrg && membershipOrg.role !== "admin")} | ||
> | ||
{`Delete ${currentOrg?.name}`} | ||
</Button> | ||
<DeleteActionModal | ||
isOpen={popUp.deleteOrg.isOpen} | ||
title="Are you sure want to delete this organization?" | ||
subTitle={`Permanently remove ${currentOrg?.name} and all of its data. This action is not reversible, so please be careful.`} | ||
onChange={(isOpen) => handlePopUpToggle("deleteOrg", isOpen)} | ||
deleteKey="confirm" | ||
onDeleteApproved={handleDeleteOrgSubmit} | ||
/> | ||
</div> | ||
); | ||
} | ||
return ( | ||
<div className="p-4 bg-mineshaft-900 rounded-lg border border-mineshaft-600 mb-6"> | ||
<p className="text-xl font-semibold text-mineshaft-100 mb-4">Danger Zone</p> | ||
<Button | ||
isLoading={isLoading} | ||
colorSchema="danger" | ||
variant="outline_bg" | ||
type="submit" | ||
onClick={() => handlePopUpOpen("deleteOrg")} | ||
isDisabled={Boolean(membership && membership.role !== "admin")} | ||
> | ||
{`Delete ${currentOrg?.name}`} | ||
</Button> | ||
<DeleteActionModal | ||
isOpen={popUp.deleteOrg.isOpen} | ||
title="Are you sure want to delete this organization?" | ||
subTitle={`Permanently remove ${currentOrg?.name} and all of its data. This action is not reversible, so please be careful.`} | ||
onChange={(isOpen) => handlePopUpToggle("deleteOrg", isOpen)} | ||
deleteKey="confirm" | ||
onDeleteApproved={handleDeleteOrgSubmit} | ||
/> | ||
</div> | ||
); | ||
}; |
13 changes: 3 additions & 10 deletions
13
frontend/src/views/Settings/OrgSettingsPage/components/OrgGeneralTab/OrgGeneralTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,17 @@ | ||
import { useOrganization, useUser } from "@app/context"; | ||
import { useGetOrgUsers } from "@app/hooks/api"; | ||
import { useOrgPermission } from "@app/context"; | ||
|
||
import { OrgDeleteSection } from "../OrgDeleteSection"; | ||
import { OrgIncidentContactsSection } from "../OrgIncidentContactsSection"; | ||
import { OrgNameChangeSection } from "../OrgNameChangeSection"; | ||
|
||
export const OrgGeneralTab = () => { | ||
const { currentOrg } = useOrganization(); | ||
const { user } = useUser(); | ||
const { data: members } = useGetOrgUsers(currentOrg?._id ?? ""); | ||
|
||
const membershipOrg = members?.find((member) => member.user._id === user?._id); | ||
const { membership } = useOrgPermission(); | ||
|
||
return ( | ||
<div> | ||
<OrgNameChangeSection /> | ||
<OrgIncidentContactsSection /> | ||
{(membershipOrg && membershipOrg.role === "admin") && ( | ||
<OrgDeleteSection /> | ||
)} | ||
{membership && membership.role === "admin" && <OrgDeleteSection />} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters