diff --git a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/(specific-project-pages)/AddTFVarForm.tsx b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/(specific-project-pages)/AddTFVarForm.tsx new file mode 100644 index 00000000..a0061296 --- /dev/null +++ b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/(specific-project-pages)/AddTFVarForm.tsx @@ -0,0 +1,146 @@ +"use client"; + +import { Button } from "@/components/ui/button"; +import { Card } from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; +import { T } from "@/components/ui/Typography"; +import { addTFVar } from "@/data/admin/env-vars"; +import { useSAToastMutation } from "@/hooks/useSAToastMutation"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { Plus } from "lucide-react"; +import { useState } from "react"; +import { Controller, useForm } from "react-hook-form"; +import { z } from "zod"; + + + + +export default function AddTFVarForm({ + projectId, + organizationId, + isAllowedSecrets, + envVarNames, +}: { + projectId: string; + organizationId: string; + isAllowedSecrets: boolean; + envVarNames: string[]; +}) { + const [showForm, setShowForm] = useState(false); + + const addTFVarSchema = z.object({ + name: z.string() + .min(1, "Name is required") + .refine((value) => !envVarNames.includes(value), { + message: "Environment variable name already exists", + }), + value: z.string().min(1, "Value is required"), + is_secret: z.boolean(), + }); + + const { mutate: addEnvVar, isLoading: isAddingEnvVar } = useSAToastMutation( + async (data: z.infer) => + addTFVar(data.name, data.value, data.is_secret, projectId, organizationId), + { + loadingMessage: "Adding environment variable...", + successMessage: "Environment variable added!", + errorMessage: "Failed to add environment variable", + onSuccess: () => { + reset(); + setShowForm(false); + }, + } + ) + + const { handleSubmit, register, reset, control, watch, formState: { errors } } = useForm>({ + resolver: zodResolver(addTFVarSchema), + defaultValues: { + name: '', + value: '', + is_secret: false, + }, + }); + + const onSubmit = (data: z.infer) => { + addEnvVar(data); + } + + return ( + <> + {showForm ? ( + + Add a new environment variable + Enter the environment variable details. These variables will be assigned to your project +
+
+
+ + e.target.value = e.target.value.toUpperCase()} + className={errors.name ? "border-destructive" : ""} + /> + {errors.name &&

{errors.name.message}

} +
+
+ + ( + + )} + /> + {errors.value &&

{errors.value.message}

} +
+
+ + ( + + )} + /> +
+
+
+ +
+
+
+ ) : ( +
+ +
+ )} + + ); +} \ No newline at end of file diff --git a/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/(specific-project-pages)/BulkEditTFVars.tsx b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/(specific-project-pages)/BulkEditTFVars.tsx new file mode 100644 index 00000000..e4ebabd9 --- /dev/null +++ b/src/app/(dynamic-pages)/(authenticated-pages)/(application-pages)/project/[projectSlug]/(specific-project-pages)/BulkEditTFVars.tsx @@ -0,0 +1,48 @@ +'use client' + +import { Button } from "@/components/ui/button"; +import { Textarea } from "@/components/ui/textarea"; +import { bulkUpdateTFVars } from "@/data/admin/env-vars"; +import { useSAToastMutation } from "@/hooks/useSAToastMutation"; +import { useState } from "react"; + +export function BulkEditTFVars({ projectId, organizationId, initialBulkEditValue, setIsBulkEditing }: { + projectId: string; + organizationId: string; + initialBulkEditValue: string; + setIsBulkEditing: (value: boolean) => void; +}) { + const [bulkEditValue, setBulkEditValue] = useState(initialBulkEditValue); + + + const { mutate: bulkEditTFVars, isLoading: isBulkEditingTFVars } = useSAToastMutation( + async (data: string) => bulkUpdateTFVars(data, projectId, organizationId), { + loadingMessage: "Applying bulk edit...", + successMessage: "Bulk edit applied!", + errorMessage: "Failed to apply bulk edit", + onSuccess: (response) => { + setBulkEditValue(JSON.stringify(response, null, 2)); + setIsBulkEditing(false); + }, + } + ) + + return ( +
+