Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

feat: added notNull to description #273

Merged
merged 3 commits into from
Aug 12, 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
24 changes: 16 additions & 8 deletions client/src/pages/user/create-events.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
/**
* SPDX-FileCopyrightText: 2024 Ng Jun Xiang <[email protected]>
*
* SPDX-License-Identifier: GPL-3.0-only
*/

import { useState } from 'react';
import { useForm, useFormState } from 'react-hook-form';

Expand All @@ -23,7 +17,7 @@ import { z } from 'zod';
import httpClient from '@utils/http';
import { eventSchema } from '@lib/api-types/schemas/event';
import { PageComponent } from '@pages/route-map';
// Define the Event type using z.infer and eventSchema

type Event = z.infer<typeof eventSchema>;

const EventCreationPage: PageComponent = () => {
Expand All @@ -46,7 +40,6 @@ const EventCreationPage: PageComponent = () => {

const handleSave = async (data: Event) => {
try {
// Prepare the payload with Date object
const payload = {
...data,
date: new Date(
Expand Down Expand Up @@ -88,6 +81,9 @@ const EventCreationPage: PageComponent = () => {
<FormField
control={eventForm.control}
name="title"
rules={{
required: 'Title is required',
}}
render={({ field, fieldState }) => (
<FormItem>
<FormLabel>Title</FormLabel>
Expand All @@ -110,6 +106,9 @@ const EventCreationPage: PageComponent = () => {
<FormField
control={eventForm.control}
name="date"
rules={{
required: 'Date is required',
}}
render={({ field, fieldState }) => (
<FormItem>
<FormLabel>Date</FormLabel>
Expand Down Expand Up @@ -138,6 +137,9 @@ const EventCreationPage: PageComponent = () => {
<FormField
control={eventForm.control}
name="time"
rules={{
required: 'Time is required',
}}
render={({ field, fieldState }) => (
<FormItem>
<FormLabel>Time</FormLabel>
Expand All @@ -162,6 +164,9 @@ const EventCreationPage: PageComponent = () => {
<FormField
control={eventForm.control}
name="location"
rules={{
required: 'Location is required',
}}
render={({ field, fieldState }) => (
<FormItem>
<FormLabel>Location</FormLabel>
Expand All @@ -184,6 +189,9 @@ const EventCreationPage: PageComponent = () => {
<FormField
control={eventForm.control}
name="description"
rules={{
required: 'Description is required',
}}
render={({ field, fieldState }) => (
<FormItem>
<FormLabel>Description</FormLabel>
Expand Down
2 changes: 1 addition & 1 deletion client/src/pages/user/event-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const EventList: PageComponent = () => {
<h2 className="text-xl font-semibold">{event.title}</h2>
<p>{`${event.date} ${event.time}`}</p>
<p>{event.location}</p>
<p>{event.description || 'No description available'}</p>
<p>{event.description}</p>
<button
className="mt-2 rounded bg-red-500 px-4 py-2 text-white hover:bg-red-600"
onClick={() => deleteEvent(event.id)}
Expand Down
1 change: 1 addition & 0 deletions server/migrations/0024_military_master_chief.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "events" ALTER COLUMN "description" SET NOT NULL;
Loading