Skip to content

Commit

Permalink
Feat: finished admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauritzskog committed Sep 27, 2024
1 parent 27705ca commit 4c065ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 5 additions & 5 deletions frontend/src/app/api/arrangementer/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ export async function PUT(
try {
const { id } = params;
const body = await req.json();
const validatedData = createArrangementSchema.parse({
...body,
});

// console.log(body);
// const validatedData = createArrangementSchema.parse({
// ...body,
// });
const updatedEvent = await db.arrangement.update({
where: { id },
data: validatedData,
data: body,
});

if (!updatedEvent) {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/components/admin/arrangementForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ const ArrangementComponentNew = () => {
const [imagePreview, setImagePreview] = useState<string | null>(null);
const [isEditMode, setIsEditMode] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);
const [refreshKey, setRefreshKey] = useState<number>(0);
const { data, loading, error } = useFetch<{ data: Arrangement[] }>(
"/api/arrangementer",
refreshKey,
);

const form = useForm<z.infer<typeof createArrangementSchema>>({
Expand All @@ -78,7 +80,7 @@ const ArrangementComponentNew = () => {
if (data && data.data) {
setEvents(data.data);
}
}, [data]);
}, [data, refreshKey]);

const handleCreateEvent = () => {
setSelectedEvent(null);
Expand Down Expand Up @@ -221,6 +223,7 @@ const ArrangementComponentNew = () => {
setImageFile(null);
setImagePreview(null);
setIsModalOpen(false);
setRefreshKey((prevState) => prevState + 1);
} catch (error) {
console.error("Error submitting form:", error);
} finally {
Expand Down Expand Up @@ -349,7 +352,7 @@ const ArrangementComponentNew = () => {
</Dialog>

<Dialog open={isModalOpen} onOpenChange={setIsModalOpen}>
<DialogContent className="sm:max-w-[425px]">
<DialogContent className="sm:max-w-[425px] max-h-[90vh] overflow-y-scroll">
<DialogHeader>
<DialogTitle>
{isEditMode ? "Rediger arrangement" : "Lag nytt arrangement"}
Expand Down

0 comments on commit 4c065ef

Please sign in to comment.