import { type ChangeEvent, useRef, useState } from "react"; import { toast } from "sonner"; import { LoadingButton } from "~/components/ui/button"; import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "~/components/ui/form"; import { Input } from "~/components/ui/input"; import { GenerateServiceAccountB64 } from "~/actions/configuration"; import { type FormProps, FormSection } from "./ConfiguratorPage"; export default function EnvironmentForm({ onResetField, form }: FormProps) { const serviceInputRef = useRef(null); const [serviceInputLoading, setServiceInputLoading] = useState(false); function onLoadServiceAccount(e: ChangeEvent) { setServiceInputLoading(true); toast.loading("Processing service account file", { id: "service-account", }); try { const file = e.target.files?.[0]; if (!file) throw new Error("No file selected"); const fr = new FileReader(); fr.onload = async () => { if (!fr.result) throw new Error("Failed to read file content"); const stringResult = typeof fr.result === "object" ? JSON.stringify(fr.result) : String(fr.result); const b64 = await GenerateServiceAccountB64(stringResult); if (!b64.success) throw new Error(b64.error); form.setValue("environment.GD_SERVICE_B64", b64.data); toast.success("Service account encoded", { id: "service-account", }); }; fr.readAsText(file); } catch (error) { const e = error as Error; console.error(e.message); toast.error("Failed to load service account file", { description: e.message, id: "service-account", }); } finally { e.target.value = ""; // Reset file input wether success or not setServiceInputLoading(false); } } return ( ( { onResetField?.("environment.GD_SERVICE_B64"); }} > Service Account
serviceInputRef.current?.click()} type='button' > Load JSON
Load your service account JSON file to get the base64 encoded string.
)} /> ( { onResetField?.("environment.ENCRYPTION_KEY"); }} > Encryption Key Secret encryption key to protect sensitive data. )} /> ( { onResetField?.("environment.SITE_PASSWORD"); }} > Private Index Password Will be used if you set the index to private. )} /> ( { onResetField?.("environment.NEXT_PUBLIC_DOMAIN"); }} > Site Domain The domain for the site, without the protocol.
Needed if you deploy outside of Vercel.
)} />
); }