2024-08-07 16:37:54 -05:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
|
|
|
import { useForm } from "react-hook-form";
|
|
|
|
|
import { z } from "zod";
|
|
|
|
|
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import {
|
2024-11-10 20:57:08 -06:00
|
|
|
Form,
|
|
|
|
|
FormControl,
|
|
|
|
|
FormField,
|
|
|
|
|
FormItem,
|
|
|
|
|
FormLabel,
|
|
|
|
|
FormMessage,
|
2024-08-07 16:37:54 -05:00
|
|
|
} from "@/components/ui/form";
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { setCustomization } from "@/lib/api";
|
|
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import toast from "react-hot-toast";
|
2024-11-10 20:57:08 -06:00
|
|
|
import ColorProvider from "../ColorProvider";
|
2024-08-07 16:37:54 -05:00
|
|
|
|
|
|
|
|
const FormSchema = z.object({
|
2024-11-10 20:57:08 -06:00
|
|
|
website: z
|
|
|
|
|
.string()
|
|
|
|
|
.min(2, {
|
|
|
|
|
message: "ID must be at least 2 characters.",
|
|
|
|
|
})
|
|
|
|
|
.url({ message: "Image must be in URL form." }),
|
2024-08-07 16:37:54 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export function BannerPopover({ server, get }: { server: string; get: any }) {
|
2024-11-10 20:57:08 -06:00
|
|
|
const form = useForm<z.infer<typeof FormSchema>>({
|
|
|
|
|
resolver: zodResolver(FormSchema),
|
|
|
|
|
defaultValues: {
|
|
|
|
|
website: "",
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-08-07 16:37:54 -05:00
|
|
|
|
2024-11-10 20:57:08 -06:00
|
|
|
async function onSubmit(data: z.infer<typeof FormSchema>) {
|
|
|
|
|
toast.promise(setCustomization(server, { banner: imageId }), {
|
|
|
|
|
loading: "Setting banner..",
|
|
|
|
|
success: "Set banner!",
|
|
|
|
|
error: "Error while setting banner",
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-08-07 16:37:54 -05:00
|
|
|
|
2024-11-10 20:57:08 -06:00
|
|
|
return (
|
|
|
|
|
<ColorProvider server={server} fetch={get}>
|
|
|
|
|
<div>
|
|
|
|
|
<span className="text-sm">
|
|
|
|
|
All images that are in a web supported format can be used as the
|
|
|
|
|
banner for a server.
|
|
|
|
|
</span>
|
|
|
|
|
<br />
|
|
|
|
|
<br />
|
|
|
|
|
<Form {...form}>
|
|
|
|
|
<form
|
|
|
|
|
onSubmit={form.handleSubmit(onSubmit)}
|
|
|
|
|
className="w-2/3 space-y-6"
|
|
|
|
|
defaultValue={get?.banner}
|
|
|
|
|
>
|
|
|
|
|
<FormField
|
|
|
|
|
control={form.control}
|
|
|
|
|
name="website"
|
|
|
|
|
render={({ field }) => (
|
|
|
|
|
<FormItem>
|
|
|
|
|
<FormLabel>Image URL</FormLabel>
|
|
|
|
|
<FormControl>
|
|
|
|
|
<Input {...field} />
|
|
|
|
|
</FormControl>
|
|
|
|
|
<FormMessage />
|
|
|
|
|
</FormItem>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
<Button type="submit" className="h-[30px]">
|
|
|
|
|
Submit
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
className="ml-2 h-[30px]"
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
console.log("hi");
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Clear
|
|
|
|
|
</Button>
|
|
|
|
|
</form>
|
|
|
|
|
</Form>
|
|
|
|
|
</div>
|
|
|
|
|
</ColorProvider>
|
|
|
|
|
);
|
2024-08-07 16:37:54 -05:00
|
|
|
}
|