generated from chingu-voyages/voyage-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add time picker * use js dates for time picker
- Loading branch information
Showing
12 changed files
with
418 additions
and
110 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
59 changes: 59 additions & 0 deletions
59
suncityla/app/booking/components/TimeSelect/TimeSelect.tsx
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,59 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
|
||
import { | ||
Select, | ||
SelectContent, | ||
SelectGroup, | ||
SelectItem, | ||
SelectLabel, | ||
SelectTrigger, | ||
SelectValue, | ||
} from '@/components/ui/select'; | ||
import { FormField, FormItem } from '@/components/ui/form'; | ||
import { format } from 'date-fns'; | ||
|
||
export function TimeSelect({ | ||
availableTimes, | ||
selectedTime, | ||
onTimeSelect, | ||
}: { | ||
availableTimes: { from: number; to: number }[]; | ||
selectedTime?: number; | ||
onTimeSelect: (time: number) => void; | ||
}) { | ||
return ( | ||
<FormField | ||
name="" | ||
render={() => { | ||
return ( | ||
<FormItem> | ||
<Select | ||
onValueChange={(time) => onTimeSelect(Number(time))} | ||
value={selectedTime?.toString()} | ||
> | ||
<SelectTrigger className="w-[180px] bg-white"> | ||
<SelectValue placeholder="Select a time" /> | ||
</SelectTrigger> | ||
<div className="bg-white"> | ||
<SelectContent> | ||
<SelectGroup> | ||
<SelectLabel>Times</SelectLabel> | ||
{availableTimes.map(({ from, to }, i) => ( | ||
<SelectItem className="cursor-pointer" key={i} value={from.toString()}> | ||
{format(from, 'h:mm a')} - {format(to, 'h:mm a')} | ||
</SelectItem> | ||
))} | ||
</SelectGroup> | ||
</SelectContent> | ||
</div> | ||
</Select> | ||
</FormItem> | ||
); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export default TimeSelect; |
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,12 @@ | ||
const createAvailableTimes = (date: Date) => { | ||
const availableTimes = []; | ||
for (let i = 8; i < 20; i++) { | ||
availableTimes.push({ | ||
from: date.setHours(i, 0, 0, 0), | ||
to: date.setHours(i + 1, 0, 0, 0), | ||
}); | ||
} | ||
return availableTimes; | ||
}; | ||
|
||
export default createAvailableTimes; |
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.