Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add display options to types #146

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/admin-server/src/hooks/use-tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ export default function useTags(projectId?: string, id?: string) {

const tagSwr = useSWR(projectId && id ? url : null);

async function updateTag(name: string, type: string, seqnr: number) {
async function updateTag(name: string, type: string, seqnr: number, backgroundColor: string | undefined, color: string | undefined, label: string | undefined, mapIcon: string | undefined, listIcon: string | undefined) {
const res = await fetch(url, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ projectId, id, name, type, seqnr }),
body: JSON.stringify({ projectId, id, name, type, seqnr, backgroundColor, color, label, mapIcon, listIcon }),
});

return await res.json();
}

return { ...tagSwr, updateTag }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function ProjectSettings() {
<TabsList className="w-full bg-white border-b-0 mb-4 rounded-md">
<TabsTrigger value="general">Projectinformatie</TabsTrigger>
<TabsTrigger value="advanced">
Geadvanceerde instellingen
Geavanceerde instellingen
</TabsTrigger>
</TabsList>
<TabsContent value="general" className="p-0">
Expand Down
208 changes: 155 additions & 53 deletions apps/admin-server/src/pages/projects/[project]/tags/[tag]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
FormLabel,
FormMessage,
} from '@/components/ui/form';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Input } from '@/components/ui/input';
import { PageLayout } from '@/components/ui/page-layout';
import { Heading } from '@/components/ui/typography';
Expand All @@ -25,11 +26,15 @@ const formSchema = z.object({
name: z.string(),
type: z.string(),
seqnr: z.coerce.number(),
backgroundColor: z.string().optional(),
color: z.string().optional(),
label: z.string().optional(),
mapIcon: z.string().max(5000).optional(),
listIcon: z.string().optional(),
});

export default function ProjectTagEdit() {
const router = useRouter();
console.log(router);
const { project, tag } = router.query;
const { data, isLoading, updateTag } = useTag(
project as string,
Expand All @@ -41,6 +46,11 @@ export default function ProjectTagEdit() {
name: data?.name || null,
type: data?.type || null,
seqnr: data?.seqnr || null,
backgroundColor: data?.backgroundColor || undefined,
color: data?.color || undefined,
label: data?.label || undefined,
mapIcon: data?.mapIcon || undefined,
listIcon: data?.listIcon || undefined,
}),
[data]
);
Expand All @@ -51,7 +61,7 @@ export default function ProjectTagEdit() {
});

async function onSubmit(values: z.infer<typeof formSchema>) {
const tag = await updateTag(values.name, values.type, values.seqnr);
const tag = await updateTag(values.name, values.type, values.seqnr, values.backgroundColor, values.color, values.label, values.mapIcon, values.listIcon);
if (tag) {
toast.success('Tag aangepast!');
} else {
Expand Down Expand Up @@ -81,57 +91,149 @@ export default function ProjectTagEdit() {
url: `/projects/${project}/tags/${tag}`,
},
]}>
<div className="p-6 bg-white rounded-md">
<Form {...form}>
<Heading size="xl">Aanpassen</Heading>
<Separator className="my-4" />
<form
onSubmit={form.handleSubmit(onSubmit)}
className="lg:w-1/2 grid grid-cols-1 gap-4">
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Naam</FormLabel>
<FormControl>
<Input placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="type"
render={({ field }) => (
<FormItem>
<FormLabel>Type</FormLabel>
<FormControl>
<Input placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="seqnr"
render={({ field }) => (
<FormItem>
<FormLabel>Sequence nummer</FormLabel>
<FormControl>
<Input type="number" placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button className="w-fit col-span-full" type="submit">
Opslaan
</Button>
</form>
</Form>
<div className="container py-6">
<Tabs defaultValue="general">
<TabsList className="w-full bg-white border-b-0 mb-4 rounded-md">
<TabsTrigger value="general">Tag</TabsTrigger>
<TabsTrigger value="advanced">
Geavanceerde instellingen
</TabsTrigger>
</TabsList>
<TabsContent value="general" className="p-0">
<div className="p-6 bg-white rounded-md">
<Form {...form}>
<Heading size="xl">Tag Aanpassen</Heading>
<Separator className="my-4" />
<form
onSubmit={form.handleSubmit(onSubmit)}
className="lg:w-1/2 grid grid-cols-1 gap-4">
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Naam</FormLabel>
<FormControl>
<Input placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="type"
render={({ field }) => (
<FormItem>
<FormLabel>Type</FormLabel>
<FormControl>
<Input placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="seqnr"
render={({ field }) => (
<FormItem>
<FormLabel>Sequence nummer</FormLabel>
<FormControl>
<Input type="number" placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button className="w-fit col-span-full" type="submit">
Opslaan
</Button>
</form>
</Form>
</div>
</TabsContent>
<TabsContent value="advanced" className="p-0">
<div className="p-6 bg-white rounded-md">
<Form {...form}>
<Heading size="xl">Tag weergave</Heading>
<Separator className="my-4" />
<form
onSubmit={form.handleSubmit(onSubmit)}
className="lg:w-1/2 grid grid-cols-1 gap-4">
<FormField
control={form.control}
name="backgroundColor"
render={({ field }) => (
<FormItem>
<FormLabel>Achtergrond kleur</FormLabel>
<FormControl>
<Input placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="color"
render={({ field }) => (
<FormItem>
<FormLabel>Tekst kleur</FormLabel>
<FormControl>
<Input placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="label"
render={({ field }) => (
<FormItem>
<FormLabel>Label</FormLabel>
<FormControl>
<Input placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="mapIcon"
render={({ field }) => (
<FormItem>
<FormLabel>Kaart icon</FormLabel>
<FormControl>
<Input placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="listIcon"
render={({ field }) => (
<FormItem>
<FormLabel>Resource overview icon</FormLabel>
<FormControl>
<Input placeholder="" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<Button className="w-fit col-span-full" type="submit">
Opslaan
</Button>
</form>
</Form>
</div>
</TabsContent>
</Tabs>
</div>
</PageLayout>
</div>
Expand Down
Loading
Loading