design + functionality improvement

This commit is contained in:
Omer Sabic 2024-06-22 16:19:34 +02:00
parent ff0d61a071
commit 7aec066ef7
3 changed files with 90 additions and 153 deletions

View File

@ -10,11 +10,10 @@ export const load = async ({ fetch }) => {
}); });
const { site } = await blogRes.json(); const { site } = await blogRes.json();
site.primary_color_hex = "#" + site.primary_color_hex // site.primary_color_hex = "#" + site.primary_color_hex
site.secondary_color_hex = "#" + site.secondary_color_hex // site.secondary_color_hex = "#" + site.secondary_color_hex
site.text_color_hex = "#" + site.text_color_hex // site.text_color_hex = "#" + site.text_color_hex
// console.log("getting back", site)
return { return {
blog_info: site, blog_info: site,
form: await superValidate(site, zod(schema)) form: await superValidate(site, zod(schema))
@ -32,9 +31,9 @@ export const actions = {
} }
let data = structuredClone(form.data); let data = structuredClone(form.data);
data.primary_color_hex = data.primary_color_hex.slice(1); // data.primary_color_hex = data.primary_color_hex.slice(1);
data.secondary_color_hex = data.secondary_color_hex.slice(1); // data.secondary_color_hex = data.secondary_color_hex.slice(1);
data.text_color_hex = data.text_color_hex.slice(1); // data.text_color_hex = data.text_color_hex.slice(1);
const res = await event.fetch(config.api_url + "/dashboard/website", { const res = await event.fetch(config.api_url + "/dashboard/website", {
method: "PUT", method: "PUT",

View File

@ -85,18 +85,12 @@
<input type="text" value={data.blog_info.id} name="id" readonly class="hidden" /> <input type="text" value={data.blog_info.id} name="id" readonly class="hidden" />
<div class="grid grid-cols-1 gap-16 md:grid-cols-2 md:grid-rows-1"> <div class="grid grid-cols-1 gap-16 md:grid-cols-2 md:grid-rows-1">
<div> <div class="space-y-16">
<Collapsible.Root class="space-y-2"> <div class="space-y-4">
<div class="flex items-center justify-between space-x-4 border-b px-4"> <div class="flex items-center justify-between space-x-4 border-b px-4">
<h2 class="mb-4 text-2xl font-bold">Basics</h2> <h2 class="mb-4 text-2xl font-bold">Basics</h2>
<Collapsible.Trigger asChild let:builder>
<Button builders={[builder]} variant="ghost" size="sm" class="w-9 p-0">
<ChevronsUpDown class="h-4 w-4" />
<span class="sr-only">Toggle</span>
</Button>
</Collapsible.Trigger>
</div> </div>
<Collapsible.Content class="space-y-2"> <div>
<Form.Field {form} name="name"> <Form.Field {form} name="name">
<Form.Control let:attrs> <Form.Control let:attrs>
<Form.Label>Blog name</Form.Label> <Form.Label>Blog name</Form.Label>
@ -121,48 +115,48 @@
<Form.Description /> <Form.Description />
<Form.FieldErrors /> <Form.FieldErrors />
</Form.Field> </Form.Field>
<Form.Field {form} name="primary_color_hex"> <!-- <Form.Field {form} name="primary_color_hex">
<Form.Control let:attrs> <Form.Control let:attrs>
<Form.Label>Primary color</Form.Label> <Form.Label>Primary color</Form.Label>
<ColorPicker <ColorPicker
on:input={(e) => { on:input={(e) => {
if (e.detail.hex) $formData.primary_color_hex = e.detail.hex; if (e.detail.hex) $formData.primary_color_hex = e.detail.hex;
}} }}
hex={data.blog_info.primary_color_hex} hex={data.blog_info.primary_color_hex}
{...attrs} {...attrs}
/> />
</Form.Control> </Form.Control>
<Form.Description /> <Form.Description />
<Form.FieldErrors /> <Form.FieldErrors />
</Form.Field> </Form.Field>
<Form.Field {form} name="secondary_color_hex"> <Form.Field {form} name="secondary_color_hex">
<Form.Control let:attrs> <Form.Control let:attrs>
<Form.Label>Secondary color</Form.Label> <Form.Label>Secondary color</Form.Label>
<ColorPicker <ColorPicker
on:input={(e) => { on:input={(e) => {
if (e.detail.hex) $formData.secondary_color_hex = e.detail.hex; if (e.detail.hex) $formData.secondary_color_hex = e.detail.hex;
}} }}
hex={data.blog_info.secondary_color_hex} hex={data.blog_info.secondary_color_hex}
{...attrs} {...attrs}
/> />
</Form.Control> </Form.Control>
<Form.Description /> <Form.Description />
<Form.FieldErrors /> <Form.FieldErrors />
</Form.Field> </Form.Field>
<Form.Field {form} name="text_color_hex"> <Form.Field {form} name="text_color_hex">
<Form.Control let:attrs> <Form.Control let:attrs>
<Form.Label>Text color</Form.Label> <Form.Label>Text color</Form.Label>
<ColorPicker <ColorPicker
on:input={(e) => { on:input={(e) => {
if (e.detail.hex) $formData.text_color_hex = e.detail.hex; if (e.detail.hex) $formData.text_color_hex = e.detail.hex;
}} }}
hex={data.blog_info.text_color_hex} hex={data.blog_info.text_color_hex}
{...attrs} {...attrs}
/> />
</Form.Control> </Form.Control>
<Form.Description /> <Form.Description />
<Form.FieldErrors /> <Form.FieldErrors />
</Form.Field> </Form.Field> -->
<Form.Field {form} name="domain"> <Form.Field {form} name="domain">
<Form.Control let:attrs> <Form.Control let:attrs>
<Form.Label>Custom domain</Form.Label> <Form.Label>Custom domain</Form.Label>
@ -179,21 +173,43 @@
{/if} {/if}
<Form.FieldErrors /> <Form.FieldErrors />
</Form.Field> </Form.Field>
</Collapsible.Content> </div>
</Collapsible.Root> </div>
<div class="space-y-4">
<div class="flex items-center justify-between space-x-4 border-b px-4">
<h2 class="mb-4 text-2xl font-bold">Auto publish</h2>
</div>
<div>
<Form.Field {form} name="auto_publish">
<Form.Control let:attrs>
<Form.Label>Auto Publish</Form.Label>
<div class="flex items-center justify-start">
<Switch {...attrs} bind:checked={$formData.auto_publish} />
</div>
</Form.Control>
<Form.FieldErrors />
<Form.Description
>Automatically creates a blog post for you when you upload a video</Form.Description
>
</Form.Field>
</div>
</div>
</div> </div>
<div> <div class="space-y-16">
<Collapsible.Root class="space-y-2"> <div class="space-y-4">
<div class="flex items-center justify-between space-x-4 border-b px-4"> <div class="flex items-center justify-between space-x-4 border-b px-4">
<h2 class="mb-4 text-2xl font-bold">Freebies</h2> <h2 class="mb-4 text-2xl font-bold">Freebies</h2>
<Collapsible.Trigger asChild let:builder>
<Button builders={[builder]} variant="ghost" size="sm" class="w-9 p-0">
<ChevronsUpDown class="h-4 w-4" />
<span class="sr-only">Toggle</span>
</Button>
</Collapsible.Trigger>
</div> </div>
<Collapsible.Content class="space-y-2"> <div>
<Form.Field {form} name="freebie_title">
<Form.Control let:attrs>
<Form.Label class="text-right">Freebie title</Form.Label>
<div class="flex items-center justify-start">
<Input {...attrs} bind:value={$formData.freebie_title} />
</div>
</Form.Control>
<Form.FieldErrors />
</Form.Field>
<Form.Field {form} name="use_freebie"> <Form.Field {form} name="use_freebie">
<Form.Control let:attrs> <Form.Control let:attrs>
<Form.Label class="text-right">Send freebie</Form.Label> <Form.Label class="text-right">Send freebie</Form.Label>
@ -207,19 +223,6 @@
> >
</Form.Control> </Form.Control>
</Form.Field> </Form.Field>
<Form.Field {form} name="freebie_name">
<Form.Control let:attrs>
<Form.Label class="text-right">Freebie Name</Form.Label>
<div class="flex items-center justify-start">
<Input
{...attrs}
bind:value={$formData.freebie_name}
bind:readonly={disable_freebies}
/>
</div>
</Form.Control>
<Form.FieldErrors />
</Form.Field>
<Form.Field {form} name="freebie_url"> <Form.Field {form} name="freebie_url">
<Form.Control let:attrs> <Form.Control let:attrs>
<Form.Label class="text-right">Freebie file</Form.Label> <Form.Label class="text-right">Freebie file</Form.Label>
@ -276,66 +279,8 @@
>The text displayed next to the signup form on your blog.</Form.Description >The text displayed next to the signup form on your blog.</Form.Description
> >
</Form.Field> </Form.Field>
</Collapsible.Content>
</Collapsible.Root>
</div>
<div>
<Collapsible.Root class="space-y-2">
<div class="flex items-center justify-between space-x-4 border-b px-4">
<h2 class="mb-4 text-2xl font-bold">Auto publish</h2>
<Collapsible.Trigger asChild let:builder>
<Button builders={[builder]} variant="ghost" size="sm" class="w-9 p-0">
<ChevronsUpDown class="h-4 w-4" />
<span class="sr-only">Toggle</span>
</Button>
</Collapsible.Trigger>
</div> </div>
<Collapsible.Content class="space-y-2"> </div>
<Form.Field {form} name="auto_publish">
<Form.Control let:attrs>
<Form.Label>Auto Publish</Form.Label>
<div class="flex items-center justify-start">
<Switch {...attrs} bind:checked={$formData.auto_publish} />
</div>
</Form.Control>
<Form.FieldErrors />
<Form.Description
>Automatically creates a blog post for you when you upload a video</Form.Description
>
</Form.Field>
<Form.Field {form} name="freebie_name">
<Form.Control let:attrs>
<Form.Label class="text-right">Freebie Name</Form.Label>
<div class="flex items-center justify-start">
<Input
{...attrs}
bind:value={$formData.freebie_name}
bind:readonly={disable_freebies}
/>
</div>
</Form.Control>
<Form.FieldErrors />
</Form.Field>
<Form.Field {form} name="freebie_url">
<Form.Control let:attrs>
<Form.Label class="text-right">Freebie file</Form.Label>
<div class="flex items-center justify-start">
<Input
type="file"
on:input={(e) =>
handleFileChange(e, $formData.freebie_url).then((x) => {
$formData.freebie_url = x;
})}
bind:disabled={disable_freebies}
/>
<Input {...attrs} class="hidden" bind:value={$formData.freebie_url} readonly />
</div>
</Form.Control>
<Form.Description>Maximum size of 5MB (TEMPORARY)</Form.Description>
<Form.FieldErrors />
</Form.Field>
</Collapsible.Content>
</Collapsible.Root>
</div> </div>
</div> </div>
<div class="mt-4"> <div class="mt-4">

View File

@ -3,14 +3,14 @@ import { z } from "zod";
export const schema = z.object({ export const schema = z.object({
id: z.string(), id: z.string(),
name: z.string().min(4).max(32), name: z.string().min(4).max(32),
primary_color_hex: z.string().length(7), // primary_color_hex: z.string().length(7),
secondary_color_hex: z.string().length(7), // secondary_color_hex: z.string().length(7),
text_color_hex: z.string().length(7), // text_color_hex: z.string().length(7),
domain: z.string().refine((key) => key === null || /^[a-z0-9\.\-]*$/.test(key), { domain: z.string().refine((key) => key === null || /^[a-z0-9\.\-]*$/.test(key), {
message: "Invalid domain" message: "Invalid domain"
}).nullable(), }).nullable(),
use_freebie: z.boolean().default(false), use_freebie: z.boolean().default(false),
freebie_name: z.string().nullable(), freebie_title: z.string().nullable(),
freebie_url: z.string().nullable(), freebie_url: z.string().nullable(),
freebie_image_url: z.string().nullable(), freebie_image_url: z.string().nullable(),
freebie_text: z.string().nullable(), freebie_text: z.string().nullable(),
@ -20,13 +20,6 @@ export const schema = z.object({
}).superRefine((data, ctx) => { }).superRefine((data, ctx) => {
console.log(data); console.log(data);
if (data.use_freebie) { if (data.use_freebie) {
if (!data.freebie_name || data.freebie_name.length === 0) {
ctx.addIssue({
path: ['freebie_name'],
message: "A freebie name' is required when 'Use freebie' is true.",
code: "custom"
});
}
if (!data.freebie_url) { if (!data.freebie_url) {
ctx.addIssue({ ctx.addIssue({
path: ['freebie_url'], path: ['freebie_url'],