2023-11-20 15:16:49 +00:00
|
|
|
import { ReactElement, useState } from "react";
|
2023-11-25 15:53:50 +00:00
|
|
|
import Link from "next/link";
|
2023-11-20 15:16:49 +00:00
|
|
|
import useSWR from "swr";
|
|
|
|
import { observer } from "mobx-react-lite";
|
|
|
|
// layouts
|
2023-11-25 15:53:50 +00:00
|
|
|
import { InstanceAdminLayout } from "layouts/admin-layout";
|
2023-11-20 15:16:49 +00:00
|
|
|
// types
|
|
|
|
import { NextPageWithLayout } from "types/app";
|
|
|
|
// store
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
|
|
|
// hooks
|
|
|
|
import useToast from "hooks/use-toast";
|
|
|
|
// ui
|
|
|
|
import { Loader, ToggleSwitch } from "@plane/ui";
|
|
|
|
// components
|
|
|
|
import { InstanceGoogleConfigForm } from "components/instance/google-config-form";
|
|
|
|
import { InstanceGithubConfigForm } from "components/instance/github-config-form";
|
|
|
|
|
|
|
|
const InstanceAdminAuthorizationPage: NextPageWithLayout = observer(() => {
|
|
|
|
// store
|
|
|
|
const {
|
|
|
|
instance: { fetchInstanceConfigurations, formattedConfig, updateInstanceConfigurations },
|
|
|
|
} = useMobxStore();
|
|
|
|
|
|
|
|
useSWR("INSTANCE_CONFIGURATIONS", () => fetchInstanceConfigurations());
|
|
|
|
|
|
|
|
// toast
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
|
|
|
// state
|
|
|
|
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
|
|
|
|
|
|
|
|
const enableSignup = formattedConfig?.ENABLE_SIGNUP ?? "0";
|
2023-11-25 15:53:50 +00:00
|
|
|
const enableMagicLogin = formattedConfig?.ENABLE_MAGIC_LINK_LOGIN ?? "0";
|
|
|
|
// const enableEmailPassword = formattedConfig?.ENABLE_EMAIL_PASSWORD ?? "0";
|
2023-11-20 15:16:49 +00:00
|
|
|
|
2023-11-25 15:53:50 +00:00
|
|
|
const updateConfig = async (
|
|
|
|
key: "ENABLE_SIGNUP" | "ENABLE_MAGIC_LINK_LOGIN" | "ENABLE_EMAIL_PASSWORD",
|
|
|
|
value: string
|
|
|
|
) => {
|
2023-11-20 15:16:49 +00:00
|
|
|
setIsSubmitting(true);
|
|
|
|
|
|
|
|
const payload = {
|
2023-11-25 15:53:50 +00:00
|
|
|
[key]: value,
|
2023-11-20 15:16:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
await updateInstanceConfigurations(payload)
|
|
|
|
.then(() => {
|
|
|
|
setToastAlert({
|
|
|
|
title: "Success",
|
|
|
|
type: "success",
|
2023-11-25 15:53:50 +00:00
|
|
|
message: "SSO and OAuth Settings updated successfully",
|
2023-11-20 15:16:49 +00:00
|
|
|
});
|
|
|
|
setIsSubmitting(false);
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
setToastAlert({
|
|
|
|
title: "Error",
|
|
|
|
type: "error",
|
2023-11-25 15:53:50 +00:00
|
|
|
message: "Failed to update SSO and OAuth Settings",
|
2023-11-20 15:16:49 +00:00
|
|
|
});
|
|
|
|
setIsSubmitting(false);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-11-25 15:53:50 +00:00
|
|
|
<div className="flex flex-col gap-8 my-8 mx-12">
|
|
|
|
<div className="pb-3 mb-2 border-b border-custom-border-100">
|
|
|
|
<div className="text-custom-text-100 font-medium text-xl pb-1">Single sign-on and OAuth</div>
|
|
|
|
<div className="text-custom-text-300 font-normal text-sm">
|
|
|
|
Make your teams life easy by letting them sign-up with their Google and GitHub accounts, and below are the
|
|
|
|
settings.
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-20 15:16:49 +00:00
|
|
|
{formattedConfig ? (
|
2023-11-25 15:53:50 +00:00
|
|
|
<>
|
|
|
|
<div className="flex flex-col gap-12 w-full lg:w-2/5 pb-8 border-b border-custom-border-100">
|
|
|
|
<div className="flex items-center gap-14 mr-4">
|
|
|
|
<div className="grow">
|
|
|
|
<div className="text-custom-text-100 font-medium text-sm">
|
|
|
|
Turn Magic Links {Boolean(parseInt(enableMagicLogin)) ? "off" : "on"}
|
|
|
|
</div>
|
|
|
|
<div className="text-custom-text-300 font-normal text-xs">
|
|
|
|
<p>Slack-like emails for authentication.</p>
|
|
|
|
You need to have set up email{" "}
|
|
|
|
<Link href="email">
|
|
|
|
<a className="text-custom-primary-100 hover:underline">here</a>
|
|
|
|
</Link>{" "}
|
|
|
|
to enable this.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={`shrink-0 ${isSubmitting && "opacity-70"}`}>
|
|
|
|
<ToggleSwitch
|
|
|
|
value={Boolean(parseInt(enableMagicLogin))}
|
|
|
|
onChange={() => {
|
|
|
|
Boolean(parseInt(enableMagicLogin)) === true
|
|
|
|
? updateConfig("ENABLE_MAGIC_LINK_LOGIN", "0")
|
|
|
|
: updateConfig("ENABLE_MAGIC_LINK_LOGIN", "1");
|
|
|
|
}}
|
|
|
|
size="sm"
|
|
|
|
disabled={isSubmitting}
|
|
|
|
/>
|
2023-11-20 15:16:49 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-25 15:53:50 +00:00
|
|
|
<div className="flex items-center gap-14 mr-4">
|
|
|
|
<div className="grow">
|
|
|
|
<div className="text-custom-text-100 font-medium text-sm">
|
|
|
|
Let your users log in via the methods below
|
|
|
|
</div>
|
|
|
|
<div className="text-custom-text-300 font-normal text-xs">
|
|
|
|
Toggling this off will disable all previous configs. Users will only be able to login with an e-mail
|
|
|
|
and password combo.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className={`shrink-0 ${isSubmitting && "opacity-70"}`}>
|
|
|
|
<ToggleSwitch
|
|
|
|
value={Boolean(parseInt(enableSignup))}
|
|
|
|
onChange={() => {
|
|
|
|
Boolean(parseInt(enableSignup)) === true
|
|
|
|
? updateConfig("ENABLE_SIGNUP", "0")
|
|
|
|
: updateConfig("ENABLE_SIGNUP", "1");
|
|
|
|
}}
|
|
|
|
size="sm"
|
|
|
|
disabled={isSubmitting}
|
|
|
|
/>
|
|
|
|
</div>
|
2023-11-20 15:16:49 +00:00
|
|
|
</div>
|
2023-11-25 15:53:50 +00:00
|
|
|
{/* <div className="flex items-center gap-14 mr-4">
|
|
|
|
<div className="grow">
|
|
|
|
<div className="text-custom-text-100 font-medium text-sm">
|
|
|
|
Turn Email Password {Boolean(parseInt(enableEmailPassword)) ? "off" : "on"}
|
|
|
|
</div>
|
|
|
|
<div className="text-custom-text-300 font-normal text-xs">UX Copy Required!</div>
|
|
|
|
</div>
|
|
|
|
<div className={`shrink-0 ${isSubmitting && "opacity-70"}`}>
|
|
|
|
<ToggleSwitch
|
|
|
|
value={Boolean(parseInt(enableEmailPassword))}
|
|
|
|
onChange={() => {
|
|
|
|
Boolean(parseInt(enableEmailPassword)) === true
|
|
|
|
? updateConfig("ENABLE_EMAIL_PASSWORD", "0")
|
|
|
|
: updateConfig("ENABLE_EMAIL_PASSWORD", "1");
|
|
|
|
}}
|
|
|
|
size="sm"
|
|
|
|
disabled={isSubmitting}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div> */}
|
2023-11-20 15:16:49 +00:00
|
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-y-6 py-2">
|
2023-11-25 15:53:50 +00:00
|
|
|
<div className="w-full">
|
|
|
|
<div className="flex items-center justify-between py-2 border-b border-custom-border-100">
|
|
|
|
<span className="text-lg font-medium tracking-tight">Google</span>
|
|
|
|
</div>
|
|
|
|
<div className="px-2 py-6">
|
|
|
|
<InstanceGoogleConfigForm config={formattedConfig} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="w-full">
|
|
|
|
<div className="flex items-center justify-between py-2 border-b border-custom-border-100">
|
|
|
|
<span className="text-lg font-medium tracking-tight">Github</span>
|
|
|
|
</div>
|
|
|
|
<div className="px-2 py-6">
|
|
|
|
<InstanceGithubConfigForm config={formattedConfig} />
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-11-20 15:16:49 +00:00
|
|
|
</div>
|
2023-11-25 15:53:50 +00:00
|
|
|
</>
|
2023-11-20 15:16:49 +00:00
|
|
|
) : (
|
2023-11-25 15:53:50 +00:00
|
|
|
<Loader className="space-y-4">
|
|
|
|
<Loader.Item height="50px" width="50%" />
|
|
|
|
<Loader.Item height="50px" width="50%" />
|
|
|
|
<Loader.Item height="50px" width="50%" />
|
2023-11-20 15:16:49 +00:00
|
|
|
<Loader.Item height="50px" />
|
2023-11-25 15:53:50 +00:00
|
|
|
<Loader.Item height="50px" width="25%" />
|
2023-11-20 15:16:49 +00:00
|
|
|
<Loader.Item height="50px" />
|
|
|
|
<Loader.Item height="50px" width="25%" />
|
|
|
|
</Loader>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
InstanceAdminAuthorizationPage.getLayout = function getLayout(page: ReactElement) {
|
2023-11-25 15:53:50 +00:00
|
|
|
return <InstanceAdminLayout>{page}</InstanceAdminLayout>;
|
2023-11-20 15:16:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default InstanceAdminAuthorizationPage;
|