"use client"; import { useState } from "react"; import Image from "next/image"; import { observer } from "mobx-react-lite"; import useSWR from "swr"; import { Loader, ToggleSwitch, setPromiseToast } from "@plane/ui"; // components import { AuthenticationMethodCard, InstanceGoogleConfigForm } from "components/authentication"; import { PageHeader } from "@/components/core"; // hooks import { useInstance } from "@/hooks"; // icons import GoogleLogo from "@/public/logos/google-logo.svg"; const InstanceGoogleAuthenticationPage = observer(() => { // store const { fetchInstanceConfigurations, formattedConfig, updateInstanceConfigurations } = useInstance(); // state const [isSubmitting, setIsSubmitting] = useState(false); // config const enableGoogleConfig = formattedConfig?.IS_GOOGLE_ENABLED ?? ""; useSWR("INSTANCE_CONFIGURATIONS", () => fetchInstanceConfigurations()); const updateConfig = async (key: "IS_GOOGLE_ENABLED", value: string) => { setIsSubmitting(true); const payload = { [key]: value, }; const updateConfigPromise = updateInstanceConfigurations(payload); setPromiseToast(updateConfigPromise, { loading: "Saving Configuration...", success: { title: "Configuration saved", message: () => `Google authentication is now ${value ? "active" : "disabled"}.`, }, error: { title: "Error", message: () => "Failed to save configuration", }, }); await updateConfigPromise .then(() => { setIsSubmitting(false); }) .catch((err) => { console.error(err); setIsSubmitting(false); }); }; return ( <>
} config={ { Boolean(parseInt(enableGoogleConfig)) === true ? updateConfig("IS_GOOGLE_ENABLED", "0") : updateConfig("IS_GOOGLE_ENABLED", "1"); }} size="sm" disabled={isSubmitting || !formattedConfig} /> } disabled={isSubmitting || !formattedConfig} withBorder={false} />
{formattedConfig ? ( ) : ( )}
); }); export default InstanceGoogleAuthenticationPage;