Skip to content

Commit 11f22bc

Browse files
committed
Add Quick Selection for Close Dates
1 parent 5446256 commit 11f22bc

File tree

4 files changed

+57
-22
lines changed

4 files changed

+57
-22
lines changed

apps/web/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"date-fns": "^3.6.0",
3434
"lodash": "^4.17.21",
3535
"lucide-react": "^0.378.0",
36-
"moment": "^2.30.1",
3736
"next": "^14.1.1",
3837
"react": "^18.2.0",
3938
"react-dom": "^18.2.0",

package-lock.json

-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/markets/components/CreateMarketForm.tsx

+56-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import { zodResolver } from '@hookform/resolvers/zod'
44
import { PopoverClose } from '@radix-ui/react-popover'
5+
import { format, endOfDay, endOfWeek, endOfMonth, endOfYear, addMonths } from 'date-fns'
56
import _ from 'lodash'
67
import { ToggleLeftIcon, XIcon, CircleIcon, CircleDotIcon, PlusIcon, AlignLeftIcon } from 'lucide-react'
7-
import moment from 'moment'
88
import { useRouter } from 'next/navigation'
99
import { useEffect, useMemo, useState } from 'react'
1010
import { CirclePicker } from 'react-color'
@@ -80,7 +80,7 @@ export function CreateMarketForm({
8080
question: '',
8181
type: 'binary',
8282
description: '',
83-
closeDate: moment().add(1, 'month').endOf('day').toDate(),
83+
closeDate: endOfMonth(addMonths(new Date(), 1)),
8484
options: [
8585
{ name: 'Yes', color: SHUFFLED_COLORS[0] },
8686
{ name: 'No', color: SHUFFLED_COLORS[1] },
@@ -503,15 +503,60 @@ export function CreateMarketForm({
503503
<FormItem>
504504
<FormLabel>Close Date</FormLabel>
505505
<FormControl>
506-
<Input
507-
type="datetime-local"
508-
{...field}
509-
className="w-auto"
510-
onChange={(e) => {
511-
field.onChange(new Date(e.target.value))
512-
}}
513-
value={field.value ? moment(field.value).format('YYYY-MM-DDTHH:mm') : ''}
514-
/>
506+
<div>
507+
<Input
508+
type="datetime-local"
509+
{...field}
510+
className="w-auto"
511+
onChange={(e) => {
512+
field.onChange(new Date(e.target.value))
513+
}}
514+
value={field.value ? format(field.value, "yyyy-MM-dd'T'HH:mm") : ''}
515+
/>
516+
517+
<div className="mt-2 flex flex-wrap gap-2">
518+
<Button
519+
size="sm"
520+
variant={
521+
format(field.value!, 'Pp') === format(endOfDay(new Date()), 'Pp') ? 'heavy' : 'secondary'
522+
}
523+
onClick={() => field.onChange(endOfDay(new Date()).toISOString())}
524+
type="button"
525+
>
526+
Today
527+
</Button>
528+
<Button
529+
size="sm"
530+
variant={
531+
format(field.value!, 'Pp') === format(endOfWeek(new Date()), 'Pp') ? 'heavy' : 'secondary'
532+
}
533+
onClick={() => field.onChange(endOfWeek(new Date()).toISOString())}
534+
type="button"
535+
>
536+
This Week
537+
</Button>
538+
<Button
539+
size="sm"
540+
variant={
541+
format(field.value!, 'Pp') === format(endOfMonth(new Date()), 'Pp') ? 'heavy' : 'secondary'
542+
}
543+
onClick={() => field.onChange(endOfMonth(new Date()).toISOString())}
544+
type="button"
545+
>
546+
End of {format(new Date(), 'MMMM')}
547+
</Button>
548+
<Button
549+
size="sm"
550+
variant={
551+
format(field.value!, 'Pp') === format(endOfYear(new Date()), 'Pp') ? 'heavy' : 'secondary'
552+
}
553+
onClick={() => field.onChange(endOfYear(new Date()).toISOString())}
554+
type="button"
555+
>
556+
End of {format(new Date(), 'yyyy')}
557+
</Button>
558+
</div>
559+
</div>
515560
</FormControl>
516561
<FormMessage />
517562
</FormItem>

packages/ui/src/components/ui/button.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const buttonVariants = cva(
1313
heavy: 'bg-gray-600 text-white hover:bg-gray-700',
1414
destructive: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',
1515
outline: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
16-
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
16+
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/60',
1717
ghost: 'hover:bg-accent hover:text-accent-foreground',
1818
link: 'text-primary underline-offset-4 hover:underline',
1919
},

0 commit comments

Comments
 (0)