Update JSON generator: streamline install methods, enhance note type selection, and refine button behavior for better UX

This commit is contained in:
Bram Suurd 2024-11-13 19:34:25 +01:00
parent 64fd9a5dcd
commit 5dae00b172

View File

@ -23,6 +23,7 @@ import { toast } from "sonner";
import { z } from "zod"; import { z } from "zod";
import { format } from "date-fns"; import { format } from "date-fns";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { AlertColors } from "@/config/siteConfig";
const scriptSchema = z.object({ const scriptSchema = z.object({
name: z.string().min(1), name: z.string().min(1),
@ -78,31 +79,14 @@ export default function JSONGenerator() {
website: null, website: null,
logo: null, logo: null,
description: "", description: "",
install_methods: [ install_methods: [],
{
type: "default",
script: "",
resources: {
cpu: null,
ram: null,
hdd: null,
os: null,
version: null,
},
},
],
default_credentials: { default_credentials: {
username: null, username: null,
password: null, password: null,
}, },
notes: [ notes: [],
{
text: "",
type: "",
},
],
}); });
const [isCopied, setIsCopied] = useState(false) const [isCopied, setIsCopied] = useState(false);
const [isValid, setIsValid] = useState(false); const [isValid, setIsValid] = useState(false);
const [categories, setCategories] = useState<Category[]>([]); const [categories, setCategories] = useState<Category[]>([]);
@ -138,9 +122,19 @@ export default function JSONGenerator() {
const addInstallMethod = () => { const addInstallMethod = () => {
setScript((prev) => { setScript((prev) => {
const method = { const method: {
type: "default" as "default", // Ensure type matches the union type type: "default" | "alpine";
script: `/${prev.type}/${prev.slug}.sh`, // Default script path script: string;
resources: {
cpu: number | null;
ram: number | null;
hdd: number | null;
os: string | null;
version: number | null;
};
} = {
type: "default",
script: `/${prev.type}/${prev.slug}.sh`,
resources: { resources: {
cpu: null, cpu: null,
ram: null, ram: null,
@ -497,13 +491,20 @@ export default function JSONGenerator() {
</div> </div>
<Button <Button
variant="destructive" variant="destructive"
size={"sm"}
type="button"
onClick={() => removeInstallMethod(index)} onClick={() => removeInstallMethod(index)}
> >
<Trash2 className="mr-2 h-4 w-4" /> Remove Install Method <Trash2 className="mr-2 h-4 w-4" /> Remove Install Method
</Button> </Button>
</div> </div>
))} ))}
<Button onClick={addInstallMethod}> <Button
type="button"
size={"sm"}
disabled={script.install_methods.length >= 2}
onClick={addInstallMethod}
>
<PlusCircle className="mr-2 h-4 w-4" /> Add Install Method <PlusCircle className="mr-2 h-4 w-4" /> Add Install Method
</Button> </Button>
<h3 className="text-xl font-semibold">Default Credentials</h3> <h3 className="text-xl font-semibold">Default Credentials</h3>
@ -535,17 +536,32 @@ export default function JSONGenerator() {
value={note.text} value={note.text}
onChange={(e) => updateNote(index, "text", e.target.value)} onChange={(e) => updateNote(index, "text", e.target.value)}
/> />
<Input <Select
placeholder="Note Type"
value={note.type} value={note.type}
onChange={(e) => updateNote(index, "type", e.target.value)} onValueChange={(value: string) => updateNote(index, "type", value)}
/> >
<Button variant="destructive" onClick={() => removeNote(index)}> <SelectTrigger className="flex-1">
<SelectValue placeholder="Type" />
</SelectTrigger>
<SelectContent>
{Object.keys(AlertColors).map((type) => (
<SelectItem key={type} value={type}>
{type.charAt(0).toUpperCase() + type.slice(1)}
</SelectItem>
))}
</SelectContent>
</Select>
<Button
size={"sm"}
variant="destructive"
type="button"
onClick={() => removeNote(index)}
>
<Trash2 className="mr-2 h-4 w-4" /> Remove Note <Trash2 className="mr-2 h-4 w-4" /> Remove Note
</Button> </Button>
</div> </div>
))} ))}
<Button onClick={addNote}> <Button type="button" size={"sm"} onClick={addNote}>
<PlusCircle className="mr-2 h-4 w-4" /> Add Note <PlusCircle className="mr-2 h-4 w-4" /> Add Note
</Button> </Button>
</form> </form>