-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix linting error, update time picker
- Loading branch information
Showing
12 changed files
with
194 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,38 @@ | ||
"use client"; | ||
|
||
"use client" | ||
|
||
import TimePeeker from '@/components/elements/meeting/timepeeker' | ||
|
||
import { zodResolver } from "@hookform/resolvers/zod" | ||
import { useForm } from "react-hook-form" | ||
import { z } from "zod" | ||
|
||
import { Button } from "@/components/ui/button" | ||
import React, { useState } from "react"; | ||
import WeeklySchedule from "@/components/WeeklySchedule/WeeklySchedule"; | ||
import { | ||
Form, | ||
FormControl, | ||
FormDescription, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage, | ||
} from "@/components/ui/form" | ||
import { Input } from "@/components/ui/input" | ||
import { toast } from "@/components/ui/use-toast" | ||
|
||
const FormSchema = z.object({ | ||
name: z.string().min(2, { | ||
message: "Name must be at least 2 characters.", | ||
}), | ||
email: z.string().email({ | ||
message: "Invalid email address.", | ||
}), | ||
}) | ||
|
||
export function InputForm() { | ||
const form = useForm<z.infer<typeof FormSchema>>({ | ||
resolver: zodResolver(FormSchema), | ||
defaultValues: { | ||
name: "", | ||
email: "" | ||
}, | ||
}) | ||
|
||
function onSubmit(data: z.infer<typeof FormSchema>) { | ||
toast({ | ||
title: "You submitted the following values:", | ||
description: ( | ||
<pre className="mt-2 w-[340px] rounded-md bg-slate-950 p-4"> | ||
<code className="text-white">{JSON.stringify(data, null, 2)}</code> | ||
</pre> | ||
), | ||
}) | ||
} | ||
type WeeklySchedule as WeeklyScheduleType, | ||
schedule as defaultSchedule, | ||
TimePeekerSlotType, | ||
} from "@/components/WeeklySchedule/timepeeker"; | ||
|
||
const SchedulePage: React.FC = () => { | ||
const [schedule, setSchedule] = useState<WeeklyScheduleType>(defaultSchedule); | ||
|
||
const handleSlotClick = (day: string, time: string) => { | ||
setSchedule((prevSchedule) => { | ||
const newSchedule = { ...prevSchedule }; | ||
if (newSchedule[day]?.[time]) { | ||
newSchedule[day][time] = | ||
newSchedule[day][time] === TimePeekerSlotType.Available | ||
? TimePeekerSlotType.Busy | ||
: TimePeekerSlotType.Available; | ||
} | ||
newSchedule[day]?.[time] === TimePeekerSlotType.Available | ||
? TimePeekerSlotType.Busy | ||
: TimePeekerSlotType.Available; | ||
return newSchedule; | ||
}); | ||
}; | ||
|
||
return ( | ||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)} className="w-2/3 space-y-6"> | ||
<FormField | ||
control={form.control} | ||
name="name" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Your name</FormLabel> | ||
<FormControl> | ||
<Input placeholder="enter your name" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="email" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Your mail</FormLabel> | ||
<FormControl> | ||
<Input placeholder="[email protected]" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<Button type="submit" className="w-full" variant="action">Submit</Button> | ||
</form> | ||
</Form> | ||
) | ||
} | ||
|
||
|
||
export default function meeting (){ | ||
|
||
return ( | ||
<div className="container py-12 lg:py-16"> | ||
|
||
<div className="flex flex-row"> | ||
<div> | ||
<InputForm/> | ||
<Button variant="outline">Load events from Google</Button> | ||
</div> | ||
<TimePeeker /> | ||
<div className="vertline h-full bg-black w-1"></div> | ||
<TimePeeker /> | ||
</div> | ||
</div> | ||
) | ||
} | ||
<div className="container mx-auto p-4"> | ||
<h1 className="mb-4 text-2xl font-bold">Weekly Schedule</h1> | ||
<WeeklySchedule schedule={schedule} onSlotClick={handleSlotClick} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default SchedulePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import { type TimePeekerProps, TimePeekerSlotType } from "./timepeeker"; | ||
|
||
export const WeeklySchedule: React.FC<TimePeekerProps> = ({ | ||
schedule, | ||
onSlotClick, | ||
}) => { | ||
const days = Object.keys(schedule); | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument | ||
const times = days.length > 0 ? Object.keys(schedule[days[0]]) : []; | ||
|
||
const getSlotClass = (slotType: TimePeekerSlotType) => { | ||
switch (slotType) { | ||
case TimePeekerSlotType.Busy: | ||
return "bg-green-600"; | ||
case TimePeekerSlotType.Available: | ||
default: | ||
return "bg-white"; | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="grid grid-cols-8 gap-2"> | ||
<div></div> | ||
{days.map((day) => ( | ||
<div key={day} className="text-center font-semibold"> | ||
{day} | ||
</div> | ||
))} | ||
{times.map((time) => ( | ||
<React.Fragment key={time}> | ||
<div className="pr-2 text-right">{time}</div> | ||
{days.map((day) => ( | ||
<div | ||
key={`${day}-${time}`} | ||
className={`cursor-pointer border ${getSlotClass(schedule[day][time])}`} | ||
onClick={() => onSlotClick(day, time)} | ||
> | ||
| ||
</div> | ||
))} | ||
</React.Fragment> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default WeeklySchedule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export enum TimePeekerSlotType { | ||
Busy = 'Busy', | ||
Available = 'Available', | ||
} | ||
|
||
type TimeSlots = Record<string, TimePeekerSlotType>; | ||
|
||
export type WeeklySchedule = Record<string, TimeSlots>; | ||
|
||
function defaultWeeklySchedule(): WeeklySchedule { | ||
const schedule: WeeklySchedule = {}; | ||
["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"].forEach(day => { | ||
schedule[day] = {}; | ||
["9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00"].forEach(time => { | ||
(schedule[day]!)[time] = TimePeekerSlotType.Available; | ||
}); | ||
}); | ||
return schedule; | ||
} | ||
|
||
export type TimePeekerProps = { | ||
schedule: WeeklySchedule; | ||
onSlotClick: (day: string, time: string) => void; | ||
}; | ||
|
||
export const schedule = defaultWeeklySchedule(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.