|
2 | 2 |
|
3 | 3 | import { zodResolver } from '@hookform/resolvers/zod'
|
4 | 4 | import { PopoverClose } from '@radix-ui/react-popover'
|
| 5 | +import { format, endOfDay, endOfWeek, endOfMonth, endOfYear, addMonths } from 'date-fns' |
5 | 6 | import _ from 'lodash'
|
6 | 7 | import { ToggleLeftIcon, XIcon, CircleIcon, CircleDotIcon, PlusIcon, AlignLeftIcon } from 'lucide-react'
|
7 |
| -import moment from 'moment' |
8 | 8 | import { useRouter } from 'next/navigation'
|
9 | 9 | import { useEffect, useMemo, useState } from 'react'
|
10 | 10 | import { CirclePicker } from 'react-color'
|
@@ -80,7 +80,7 @@ export function CreateMarketForm({
|
80 | 80 | question: '',
|
81 | 81 | type: 'binary',
|
82 | 82 | description: '',
|
83 |
| - closeDate: moment().add(1, 'month').endOf('day').toDate(), |
| 83 | + closeDate: endOfMonth(addMonths(new Date(), 1)), |
84 | 84 | options: [
|
85 | 85 | { name: 'Yes', color: SHUFFLED_COLORS[0] },
|
86 | 86 | { name: 'No', color: SHUFFLED_COLORS[1] },
|
@@ -503,15 +503,60 @@ export function CreateMarketForm({
|
503 | 503 | <FormItem>
|
504 | 504 | <FormLabel>Close Date</FormLabel>
|
505 | 505 | <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> |
515 | 560 | </FormControl>
|
516 | 561 | <FormMessage />
|
517 | 562 | </FormItem>
|
|
0 commit comments