Skip to content

Commit

Permalink
fix: added date time picker
Browse files Browse the repository at this point in the history
  • Loading branch information
adolfokrah committed Sep 3, 2024
1 parent ff3aca0 commit 4005ea4
Show file tree
Hide file tree
Showing 13 changed files with 823 additions and 125 deletions.
18 changes: 10 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"lucide-react": "^0.417.0",
"next-themes": "^0.3.0",
"react-colorful": "^5.6.1",
"react-day-picker": "^8.10.1",
"react-day-picker": "^9.0.8",
"react-hook-form": "^7.52.1",
"react-image-crop": "^11.0.6",
"react-jwt": "^1.2.2",
Expand Down
1 change: 1 addition & 0 deletions src/components/layout/left-side-bar/page-tab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export default function PagesTab() {
schedulePublished: page.schedule_published,
publishDate: page.publish_date ? new Date(page.publish_date) : null,
folderId: page.folder_id,
blocks: page.blocks_dev,
};
}),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Label } from '@/components/ui/label';
import { Tabs, TabsTrigger, TabsList } from '@/components/ui/tabs';
import { SchedulePublished, Status, usePagesState } from '@/lib/states/usePagesState';
import { Status, usePagesState } from '@/lib/states/usePagesState';
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
import { DatePicker } from '@/components/ui/date-picker';
import { DateTimePicker } from '@/components/ui/date-time-picker';
import usePageSettings from '@/lib/hooks/usePageSettings';

export default function PageStatusAndVisibility() {
const { handleUpdatePageDate, updateSchedulePublished, updatePageStatus, page } = usePageSettings();
const { handleUpdatePageDate, updatePageStatus, page } = usePageSettings();
const { pages } = usePagesState();
const activePage = pages.find((page) => page.active);
const activeLanguage = activePage?.activeLanguageLocale ?? '';
Expand All @@ -15,7 +15,7 @@ export default function PageStatusAndVisibility() {
<>
<Label className="!visio-cms-text-gray-300">Status</Label>
<Tabs
value={page?.status?.[activeLanguage] || 'Draft'}
value={['Publish', 'Schedule'].includes(page?.status?.[activeLanguage] || 'Draft') ? 'Publish' : 'Draft'}
className="visio-cms-w-full visio-cms-mt-3"
onValueChange={(value) => updatePageStatus(value as Status)}
>
Expand All @@ -24,35 +24,41 @@ export default function PageStatusAndVisibility() {
<TabsTrigger value="Publish">Publish</TabsTrigger>
</TabsList>
</Tabs>
{page?.status?.[activeLanguage] == 'Publish' && (
<div className="visio-cms-mt-3 visio-cms-hidden">
{['Publish', 'Schedule'].includes(page?.status?.[activeLanguage] || 'Draft') && (
<div className="visio-cms-mt-3 ">
<Label className="!visio-cms-text-gray-300">Schedule published</Label>
<div className="visio-cms-my-3">
<RadioGroup
value={page?.schedulePublished || ''}
value={page?.status?.[activeLanguage] || ''}
onValueChange={(value) => {
updateSchedulePublished(value as SchedulePublished);
updatePageStatus(value as Status);
}}
>
<div className="visio-cms-flex visio-cms-items-center visio-cms-space-x-2">
<RadioGroupItem value="Now" id="Now" />
<Label htmlFor="Now">Now</Label>
<RadioGroupItem value="Publish" id="publish" />
<Label htmlFor="publish">Now</Label>
</div>
<div className="visio-cms-flex visio-cms-items-center visio-cms-space-x-2">
<RadioGroupItem value="Later" id="Later" />
<Label htmlFor="Later">Later</Label>
<RadioGroupItem value="Schedule" id="schedule" />
<Label htmlFor="schedule">Later</Label>
</div>
</RadioGroup>
</div>
{page?.schedulePublished === 'Later' && (
{page?.status?.[activeLanguage] === 'Schedule' && (
<>
<Label className="!visio-cms-text-gray-300">Date & Time</Label>
<div className="visio-cms-my-3">
<DatePicker
key={`${page?.publishDate}`}
selectedDate={page?.publishDate || new Date()}
onSelect={handleUpdatePageDate}
disabled={{ before: new Date() }}
<DateTimePicker
disabledDays={{ before: new Date() }}
hourCycle={12}
value={page?.publishDate || new Date()}
onChange={(date) => {
if (page?.publishDate != date) {
if (date) {
handleUpdatePageDate(date);
}
}
}}
/>
</div>
</>
Expand Down
5 changes: 0 additions & 5 deletions src/components/ui/calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as React from 'react';
import { ChevronLeftIcon, ChevronRightIcon } from '@radix-ui/react-icons';
import { DayPicker } from 'react-day-picker';

import { cn } from '@/lib/utils';
Expand Down Expand Up @@ -52,10 +51,6 @@ function Calendar({ className, classNames, showOutsideDays = true, ...props }: C
day_hidden: 'visio-cms-invisible',
...classNames,
}}
components={{
IconLeft: () => <ChevronLeftIcon className="visio-cms-h-4 visio-cms-w-4" />,
IconRight: () => <ChevronRightIcon className="visio-cms-h-4 visio-cms-w-4" />,
}}
{...props}
/>
);
Expand Down
47 changes: 0 additions & 47 deletions src/components/ui/date-picker.tsx

This file was deleted.

Loading

0 comments on commit 4005ea4

Please sign in to comment.