Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
FieldLabel,
Input
} from "@app/components/v3";
import { useCreateOrg, useSelectOrganization } from "@app/hooks/api";
import { useCreateOrg, useLogoutUser, useSelectOrganization } from "@app/hooks/api";
import { GenericResourceNameSchema } from "@app/lib/schemas";

const schema = z
Expand All @@ -31,9 +31,10 @@ export type FormData = z.infer<typeof schema>;
interface CreateOrgModalProps {
isOpen: boolean;
onClose?: () => void;
logoutOnClose?: boolean;
}

export const CreateOrgModal: FC<CreateOrgModalProps> = ({ isOpen, onClose }) => {
export const CreateOrgModal: FC<CreateOrgModalProps> = ({ isOpen, onClose, logoutOnClose }) => {
const navigate = useNavigate();

const {
Expand All @@ -52,6 +53,7 @@ export const CreateOrgModal: FC<CreateOrgModalProps> = ({ isOpen, onClose }) =>
invalidate: false
});
const { mutateAsync: selectOrg } = useSelectOrganization();
const logout = useLogoutUser();

const onFormSubmit = async ({ name }: FormData) => {
const organization = await createOrg({ name });
Expand All @@ -74,16 +76,20 @@ export const CreateOrgModal: FC<CreateOrgModalProps> = ({ isOpen, onClose }) =>
onClose?.();
};

const handleOpenChange = async (open: boolean) => {
if (!open) {
reset();
if (logoutOnClose) {
await logout.mutateAsync();
navigate({ to: "/login" });
} else {
onClose?.();
}
}
};

return (
<Dialog
open={isOpen}
onOpenChange={(open) => {
if (!open) {
reset();
onClose?.();
}
}}
>
<Dialog open={isOpen} onOpenChange={handleOpenChange}>
<DialogContent className="max-w-md">
<DialogHeader>
<DialogTitle>Create Organization</DialogTitle>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/organization/NoOrgPage/NoOrgPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const NoOrgPage = () => {
<link rel="icon" href="/infisical.ico" />
</Helmet>
<div className="min-h-screen bg-bunker-800">
<CreateOrgModal isOpen />
<CreateOrgModal isOpen logoutOnClose />
</div>
</>
);
Expand Down
Loading