@carlonicora/nextjs-jsonapi 0.0.1 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BlockNoteEditor-VFWG6LXI.js.map +1 -1
- package/dist/JsonApiRequest-ZZLSP26T.js.map +1 -1
- package/dist/atoms/index.js.map +1 -1
- package/dist/chunk-2K3Q24UF.js.map +1 -1
- package/dist/chunk-3FBCC4G3.js.map +1 -1
- package/dist/chunk-4HCRAOS5.js.map +1 -1
- package/dist/chunk-6GKHCVF6.js.map +1 -1
- package/dist/chunk-7QVYU63E.js.map +1 -1
- package/dist/chunk-A5DDIABK.js.map +1 -1
- package/dist/chunk-AWONBQQP.js.map +1 -1
- package/dist/chunk-CXQOWQSY.js.map +1 -1
- package/dist/chunk-DO2HLAZO.js.map +1 -1
- package/dist/chunk-EFJEWLRL.js.map +1 -1
- package/dist/chunk-FY4SXJGU.js.map +1 -1
- package/dist/chunk-H6FMOA6B.js.map +1 -1
- package/dist/chunk-I2REI7OA.js.map +1 -1
- package/dist/chunk-IBS6NI7D.js.map +1 -1
- package/dist/chunk-J4Q36PMP.js.map +1 -1
- package/dist/chunk-JC3WJK65.js.map +1 -1
- package/dist/chunk-LXKSUWAV.js.map +1 -1
- package/dist/chunk-RAF7PNLG.js.map +1 -1
- package/dist/chunk-RUR22SVM.js.map +1 -1
- package/dist/chunk-TEGF6ZWG.js.map +1 -1
- package/dist/chunk-TMVHSY3Y.js.map +1 -1
- package/dist/chunk-V2JJPI7N.js.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/contexts/index.js.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/features/index.js.map +1 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.js.map +1 -1
- package/dist/permissions/index.js.map +1 -1
- package/dist/request-QFS7NEIE.js.map +1 -1
- package/dist/request-ZYY6RI5X.js.map +1 -1
- package/dist/roles/index.js.map +1 -1
- package/dist/server/index.js.map +1 -1
- package/dist/shadcnui/index.js.map +1 -1
- package/dist/token-MJMC26ON.js.map +1 -1
- package/dist/token-UYE7CV6X.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +6 -1
- package/src/atoms/index.ts +1 -0
- package/src/atoms/recentPagesAtom.ts +10 -0
- package/src/client/context/JsonApiContext.ts +61 -0
- package/src/client/context/JsonApiProvider.tsx +27 -0
- package/src/client/context/index.ts +2 -0
- package/src/client/hooks/index.ts +3 -0
- package/src/client/hooks/useJsonApiGet.ts +188 -0
- package/src/client/hooks/useJsonApiMutation.ts +193 -0
- package/src/client/hooks/useRehydration.ts +47 -0
- package/src/client/index.ts +11 -0
- package/src/client/request.ts +97 -0
- package/src/client/token.ts +10 -0
- package/src/components/containers/PageContainer.tsx +15 -0
- package/src/components/containers/ReactMarkdownContainer.tsx +119 -0
- package/src/components/containers/TabsContainer.tsx +93 -0
- package/src/components/containers/index.ts +3 -0
- package/src/components/contents/AttributeElement.tsx +20 -0
- package/src/components/contents/index.ts +1 -0
- package/src/components/details/AllowedUsersDetails.tsx +23 -0
- package/src/components/details/index.ts +1 -0
- package/src/components/editors/BlockNoteDiffInlineContent.tsx +152 -0
- package/src/components/editors/BlockNoteEditor.tsx +404 -0
- package/src/components/editors/BlockNoteEditorContainer.tsx +13 -0
- package/src/components/editors/BlockNoteEditorFormattingToolbar.tsx +38 -0
- package/src/components/editors/index.ts +1 -0
- package/src/components/errors/ErrorDetails.tsx +41 -0
- package/src/components/errors/errorToast.ts +9 -0
- package/src/components/errors/index.ts +2 -0
- package/src/components/forms/CommonAssociationForm.tsx +162 -0
- package/src/components/forms/CommonDeleter.tsx +94 -0
- package/src/components/forms/CommonEditorButtons.tsx +30 -0
- package/src/components/forms/CommonEditorHeader.tsx +35 -0
- package/src/components/forms/CommonEditorTrigger.tsx +26 -0
- package/src/components/forms/DatePickerPopover.tsx +219 -0
- package/src/components/forms/DateRangeSelector.tsx +110 -0
- package/src/components/forms/FileUploader.tsx +324 -0
- package/src/components/forms/FormCheckbox.tsx +66 -0
- package/src/components/forms/FormContainerGeneric.tsx +39 -0
- package/src/components/forms/FormDate.tsx +247 -0
- package/src/components/forms/FormDateTime.tsx +231 -0
- package/src/components/forms/FormInput.tsx +110 -0
- package/src/components/forms/FormPassword.tsx +54 -0
- package/src/components/forms/FormPlaceAutocomplete.tsx +286 -0
- package/src/components/forms/FormSelect.tsx +72 -0
- package/src/components/forms/FormSlider.tsx +51 -0
- package/src/components/forms/FormSwitch.tsx +25 -0
- package/src/components/forms/FormTextarea.tsx +44 -0
- package/src/components/forms/MultiFileUploader.tsx +107 -0
- package/src/components/forms/PasswordInput.tsx +47 -0
- package/src/components/forms/index.ts +21 -0
- package/src/components/index.ts +11 -0
- package/src/components/navigations/Breadcrumb.tsx +83 -0
- package/src/components/navigations/ContentTitle.tsx +39 -0
- package/src/components/navigations/Header.tsx +27 -0
- package/src/components/navigations/ModeToggleSwitch.tsx +25 -0
- package/src/components/navigations/PageSection.tsx +64 -0
- package/src/components/navigations/RecentPagesNavigator.tsx +52 -0
- package/src/components/navigations/index.ts +6 -0
- package/src/components/pages/PageContainerContentDetails.tsx +76 -0
- package/src/components/pages/PageContentContainer.tsx +31 -0
- package/src/components/pages/index.ts +2 -0
- package/src/components/tables/ContentListTable.tsx +165 -0
- package/src/components/tables/ContentTableSearch.tsx +105 -0
- package/src/components/tables/cells/cell.component.tsx +18 -0
- package/src/components/tables/cells/cell.date.tsx +16 -0
- package/src/components/tables/cells/cell.id.tsx +27 -0
- package/src/components/tables/cells/cell.link.tsx +18 -0
- package/src/components/tables/cells/cell.text.tsx +12 -0
- package/src/components/tables/cells/cell.url.tsx +13 -0
- package/src/components/tables/cells/index.ts +5 -0
- package/src/components/tables/index.ts +3 -0
- package/src/contexts/SharedContext.tsx +35 -0
- package/src/contexts/index.ts +2 -0
- package/src/core/abstracts/AbstractApiData.ts +138 -0
- package/src/core/abstracts/AbstractService.ts +263 -0
- package/src/core/abstracts/index.ts +2 -0
- package/src/core/endpoint/EndpointCreator.ts +97 -0
- package/src/core/endpoint/index.ts +1 -0
- package/src/core/factories/JsonApiDataFactory.ts +12 -0
- package/src/core/factories/RehydrationFactory.ts +30 -0
- package/src/core/factories/index.ts +2 -0
- package/src/core/fields/FieldSelector.ts +15 -0
- package/src/core/fields/index.ts +1 -0
- package/src/core/index.ts +20 -0
- package/src/core/interfaces/ApiData.ts +8 -0
- package/src/core/interfaces/ApiDataInterface.ts +15 -0
- package/src/core/interfaces/ApiRequestDataTypeInterface.ts +14 -0
- package/src/core/interfaces/ApiResponseInterface.ts +17 -0
- package/src/core/interfaces/JsonApiHydratedDataInterface.ts +5 -0
- package/src/core/interfaces/index.ts +5 -0
- package/src/core/registry/DataClassRegistry.ts +51 -0
- package/src/core/registry/ModuleRegistrar.ts +43 -0
- package/src/core/registry/ModuleRegistry.ts +64 -0
- package/src/core/registry/index.ts +3 -0
- package/src/core/utils/index.ts +2 -0
- package/src/core/utils/rehydrate.ts +24 -0
- package/src/core/utils/translateResponse.ts +125 -0
- package/src/features/auth/auth.module.ts +9 -0
- package/src/features/auth/config.ts +57 -0
- package/src/features/auth/data/auth.interface.ts +31 -0
- package/src/features/auth/data/auth.service.ts +159 -0
- package/src/features/auth/data/auth.ts +54 -0
- package/src/features/auth/data/index.ts +3 -0
- package/src/features/auth/index.ts +3 -0
- package/src/features/company/company.module.ts +10 -0
- package/src/features/company/data/company.fields.ts +6 -0
- package/src/features/company/data/company.interface.ts +28 -0
- package/src/features/company/data/company.service.ts +73 -0
- package/src/features/company/data/company.ts +104 -0
- package/src/features/company/data/index.ts +4 -0
- package/src/features/company/index.ts +2 -0
- package/src/features/content/content.module.ts +20 -0
- package/src/features/content/data/content.fields.ts +13 -0
- package/src/features/content/data/content.interface.ts +23 -0
- package/src/features/content/data/content.service.ts +75 -0
- package/src/features/content/data/content.ts +85 -0
- package/src/features/content/data/index.ts +4 -0
- package/src/features/content/index.ts +2 -0
- package/src/features/feature/components/forms/FormFeatures.tsx +149 -0
- package/src/features/feature/components/index.ts +1 -0
- package/src/features/feature/data/feature.interface.ts +9 -0
- package/src/features/feature/data/feature.service.ts +19 -0
- package/src/features/feature/data/feature.ts +33 -0
- package/src/features/feature/data/index.ts +3 -0
- package/src/features/feature/feature.module.ts +10 -0
- package/src/features/feature/index.ts +3 -0
- package/src/features/index.ts +12 -0
- package/src/features/module/data/index.ts +2 -0
- package/src/features/module/data/module.interface.ts +12 -0
- package/src/features/module/data/module.ts +42 -0
- package/src/features/module/index.ts +2 -0
- package/src/features/module/module.module.ts +10 -0
- package/src/features/notification/data/index.ts +4 -0
- package/src/features/notification/data/notification.fields.ts +8 -0
- package/src/features/notification/data/notification.interface.ts +14 -0
- package/src/features/notification/data/notification.service.ts +34 -0
- package/src/features/notification/data/notification.ts +51 -0
- package/src/features/notification/index.ts +2 -0
- package/src/features/notification/notification.module.ts +10 -0
- package/src/features/push/data/index.ts +3 -0
- package/src/features/push/data/push.interface.ts +8 -0
- package/src/features/push/data/push.service.ts +17 -0
- package/src/features/push/data/push.ts +18 -0
- package/src/features/push/index.ts +2 -0
- package/src/features/push/push.module.ts +10 -0
- package/src/features/role/data/index.ts +4 -0
- package/src/features/role/data/role.fields.ts +8 -0
- package/src/features/role/data/role.interface.ts +16 -0
- package/src/features/role/data/role.service.ts +117 -0
- package/src/features/role/data/role.ts +62 -0
- package/src/features/role/index.ts +2 -0
- package/src/features/role/role.module.ts +10 -0
- package/src/features/s3/data/index.ts +3 -0
- package/src/features/s3/data/s3.interface.ts +11 -0
- package/src/features/s3/data/s3.service.ts +30 -0
- package/src/features/s3/data/s3.ts +60 -0
- package/src/features/s3/index.ts +2 -0
- package/src/features/s3/s3.module.ts +10 -0
- package/src/features/search/index.ts +1 -0
- package/src/features/search/interfaces/index.ts +1 -0
- package/src/features/search/interfaces/search.result.interface.ts +3 -0
- package/src/features/user/author.module.ts +10 -0
- package/src/features/user/components/index.ts +2 -0
- package/src/features/user/components/lists/ContributorsList.tsx +41 -0
- package/src/features/user/components/lists/index.ts +1 -0
- package/src/features/user/components/widgets/UserAvatar.tsx +86 -0
- package/src/features/user/components/widgets/index.ts +1 -0
- package/src/features/user/contexts/CurrentUserContext.tsx +156 -0
- package/src/features/user/contexts/index.ts +1 -0
- package/src/features/user/data/index.ts +4 -0
- package/src/features/user/data/user.fields.ts +8 -0
- package/src/features/user/data/user.interface.ts +41 -0
- package/src/features/user/data/user.service.ts +246 -0
- package/src/features/user/data/user.ts +162 -0
- package/src/features/user/index.ts +4 -0
- package/src/features/user/user.module.ts +21 -0
- package/src/hooks/TableGeneratorRegistry.ts +53 -0
- package/src/hooks/index.ts +33 -0
- package/src/hooks/types.ts +35 -0
- package/src/hooks/url.rewriter.ts +22 -0
- package/src/hooks/useCustomD3Graph.tsx +705 -0
- package/src/hooks/useDataListRetriever.ts +349 -0
- package/src/hooks/useDebounce.ts +33 -0
- package/src/hooks/usePageUrlGenerator.ts +50 -0
- package/src/hooks/useTableGenerator.ts +16 -0
- package/src/i18n/config.ts +73 -0
- package/src/i18n/index.ts +18 -0
- package/src/index.ts +16 -0
- package/src/interfaces/breadcrumb.item.data.interface.ts +4 -0
- package/src/interfaces/d3.link.interface.ts +7 -0
- package/src/interfaces/d3.node.interface.ts +12 -0
- package/src/interfaces/index.ts +3 -0
- package/src/permissions/check.ts +127 -0
- package/src/permissions/index.ts +2 -0
- package/src/permissions/types.ts +109 -0
- package/src/roles/config.ts +46 -0
- package/src/roles/index.ts +1 -0
- package/src/server/cache.ts +28 -0
- package/src/server/index.ts +3 -0
- package/src/server/request.ts +113 -0
- package/src/server/token.ts +10 -0
- package/src/shadcnui/custom/kanban.tsx +1001 -0
- package/src/shadcnui/custom/link.tsx +18 -0
- package/src/shadcnui/custom/multi-select.tsx +382 -0
- package/src/shadcnui/index.ts +49 -0
- package/src/shadcnui/ui/accordion.tsx +52 -0
- package/src/shadcnui/ui/alert-dialog.tsx +141 -0
- package/src/shadcnui/ui/alert.tsx +43 -0
- package/src/shadcnui/ui/avatar.tsx +50 -0
- package/src/shadcnui/ui/badge.tsx +40 -0
- package/src/shadcnui/ui/breadcrumb.tsx +115 -0
- package/src/shadcnui/ui/button.tsx +51 -0
- package/src/shadcnui/ui/calendar.tsx +73 -0
- package/src/shadcnui/ui/card.tsx +43 -0
- package/src/shadcnui/ui/carousel.tsx +225 -0
- package/src/shadcnui/ui/chart.tsx +320 -0
- package/src/shadcnui/ui/checkbox.tsx +29 -0
- package/src/shadcnui/ui/collapsible.tsx +11 -0
- package/src/shadcnui/ui/command.tsx +155 -0
- package/src/shadcnui/ui/context-menu.tsx +179 -0
- package/src/shadcnui/ui/dialog.tsx +96 -0
- package/src/shadcnui/ui/drawer.tsx +89 -0
- package/src/shadcnui/ui/dropdown-menu.tsx +205 -0
- package/src/shadcnui/ui/form.tsx +138 -0
- package/src/shadcnui/ui/hover-card.tsx +29 -0
- package/src/shadcnui/ui/input.tsx +21 -0
- package/src/shadcnui/ui/label.tsx +26 -0
- package/src/shadcnui/ui/navigation-menu.tsx +168 -0
- package/src/shadcnui/ui/popover.tsx +33 -0
- package/src/shadcnui/ui/progress.tsx +25 -0
- package/src/shadcnui/ui/radio-group.tsx +37 -0
- package/src/shadcnui/ui/resizable.tsx +47 -0
- package/src/shadcnui/ui/scroll-area.tsx +40 -0
- package/src/shadcnui/ui/select.tsx +164 -0
- package/src/shadcnui/ui/separator.tsx +28 -0
- package/src/shadcnui/ui/sheet.tsx +139 -0
- package/src/shadcnui/ui/sidebar.tsx +677 -0
- package/src/shadcnui/ui/skeleton.tsx +13 -0
- package/src/shadcnui/ui/slider.tsx +25 -0
- package/src/shadcnui/ui/sonner.tsx +25 -0
- package/src/shadcnui/ui/switch.tsx +31 -0
- package/src/shadcnui/ui/table.tsx +120 -0
- package/src/shadcnui/ui/tabs.tsx +55 -0
- package/src/shadcnui/ui/textarea.tsx +24 -0
- package/src/shadcnui/ui/toggle.tsx +39 -0
- package/src/shadcnui/ui/tooltip.tsx +61 -0
- package/src/unified/JsonApiRequest.ts +325 -0
- package/src/unified/index.ts +1 -0
- package/src/utils/blocknote-diff.util.ts +815 -0
- package/src/utils/blocknote-word-diff-renderer.util.ts +413 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/compose-refs.ts +61 -0
- package/src/utils/date-formatter.ts +53 -0
- package/src/utils/exists.ts +7 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/schemas/entity.object.schema.ts +8 -0
- package/src/utils/schemas/index.ts +2 -0
- package/src/utils/schemas/user.object.schema.ts +9 -0
- package/src/utils/table-options.ts +67 -0
- package/src/utils/use-mobile.tsx +21 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { LoaderCircleIcon, Trash2Icon } from "lucide-react";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { useI18nRouter, useI18nTranslations } from "../../i18n";
|
|
6
|
+
import {
|
|
7
|
+
AlertDialog,
|
|
8
|
+
AlertDialogContent,
|
|
9
|
+
AlertDialogDescription,
|
|
10
|
+
AlertDialogHeader,
|
|
11
|
+
AlertDialogTitle,
|
|
12
|
+
AlertDialogTrigger,
|
|
13
|
+
Button,
|
|
14
|
+
} from "../../shadcnui";
|
|
15
|
+
import { errorToast } from "../errors";
|
|
16
|
+
|
|
17
|
+
type CommonDeleterProps = {
|
|
18
|
+
type: string;
|
|
19
|
+
deleteFunction: () => Promise<void>;
|
|
20
|
+
redirectTo?: string;
|
|
21
|
+
forceShow?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function CommonDeleter({ deleteFunction, redirectTo, type, forceShow }: CommonDeleterProps) {
|
|
25
|
+
const t = useI18nTranslations();
|
|
26
|
+
const router = useI18nRouter();
|
|
27
|
+
const [open, setOpen] = useState<boolean>(forceShow || false);
|
|
28
|
+
const [isDeleting, setIsDeleting] = useState<boolean>(false);
|
|
29
|
+
|
|
30
|
+
const handleDelete = async () => {
|
|
31
|
+
setIsDeleting(true);
|
|
32
|
+
try {
|
|
33
|
+
await deleteFunction();
|
|
34
|
+
|
|
35
|
+
setOpen(false);
|
|
36
|
+
if (redirectTo) router.push(redirectTo);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
errorToast({ title: t(`generic.errors.delete`), error: error });
|
|
39
|
+
}
|
|
40
|
+
setIsDeleting(false);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<AlertDialog open={open} onOpenChange={setOpen}>
|
|
45
|
+
{forceShow ? null : (
|
|
46
|
+
<AlertDialogTrigger asChild>
|
|
47
|
+
<Button size="sm" variant={"ghost"} className="text-muted-foreground hover:text-destructive">
|
|
48
|
+
<Trash2Icon />
|
|
49
|
+
</Button>
|
|
50
|
+
</AlertDialogTrigger>
|
|
51
|
+
)}
|
|
52
|
+
<AlertDialogContent className={`flex max-h-[70vh] max-w-3xl flex-col overflow-y-auto`}>
|
|
53
|
+
<AlertDialogHeader>
|
|
54
|
+
<AlertDialogTitle>{t(`generic.delete.title`, { type: t(`types.${type}`, { count: 1 }) })}</AlertDialogTitle>
|
|
55
|
+
<AlertDialogDescription>
|
|
56
|
+
{t(`generic.delete.subtitle`, { type: t(`types.${type}`, { count: 1 }) })}
|
|
57
|
+
</AlertDialogDescription>
|
|
58
|
+
</AlertDialogHeader>
|
|
59
|
+
<div className="text-destructive p-4 text-sm">
|
|
60
|
+
{t(`generic.delete.description`, { type: t(`types.${type}`, { count: 1 }) })}
|
|
61
|
+
</div>
|
|
62
|
+
<div className="flex justify-end">
|
|
63
|
+
<Button
|
|
64
|
+
className="mr-2"
|
|
65
|
+
variant={"outline"}
|
|
66
|
+
type={`button`}
|
|
67
|
+
onClick={() => setOpen(false)}
|
|
68
|
+
disabled={isDeleting}
|
|
69
|
+
>
|
|
70
|
+
{t(`generic.buttons.cancel`)}
|
|
71
|
+
</Button>
|
|
72
|
+
<Button
|
|
73
|
+
type="submit"
|
|
74
|
+
onClick={(e) => {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
handleDelete();
|
|
77
|
+
}}
|
|
78
|
+
variant={"destructive"}
|
|
79
|
+
disabled={isDeleting}
|
|
80
|
+
>
|
|
81
|
+
{isDeleting ? (
|
|
82
|
+
<>
|
|
83
|
+
{t(`generic.buttons.is_deleting`)}
|
|
84
|
+
<LoaderCircleIcon className="animate-spin-slow h-5 w-5" />
|
|
85
|
+
</>
|
|
86
|
+
) : (
|
|
87
|
+
t(`generic.buttons.delete`)
|
|
88
|
+
)}
|
|
89
|
+
</Button>
|
|
90
|
+
</div>
|
|
91
|
+
</AlertDialogContent>
|
|
92
|
+
</AlertDialog>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useTranslations } from "next-intl";
|
|
2
|
+
import { Button } from "../../shadcnui";
|
|
3
|
+
|
|
4
|
+
type CommonEditorButtonsProps = {
|
|
5
|
+
isEdit: boolean;
|
|
6
|
+
form: any;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
setOpen: (open: boolean) => void;
|
|
9
|
+
};
|
|
10
|
+
export function CommonEditorButtons({ isEdit, form, disabled, setOpen }: CommonEditorButtonsProps) {
|
|
11
|
+
const t = useTranslations();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div className="flex justify-end">
|
|
15
|
+
<Button
|
|
16
|
+
className="mr-2"
|
|
17
|
+
variant={"outline"}
|
|
18
|
+
type={`button`}
|
|
19
|
+
onClick={() => setOpen(false)}
|
|
20
|
+
data-testid={`modal-button-cancel`}
|
|
21
|
+
>
|
|
22
|
+
{t(`generic.buttons.cancel`)}
|
|
23
|
+
</Button>
|
|
24
|
+
|
|
25
|
+
<Button type="submit" disabled={form.formState.isSubmitting || disabled} data-testid={`modal-button-create`}>
|
|
26
|
+
{isEdit ? t(`generic.buttons.confirm_update`) : t(`generic.buttons.confirm_create`)}
|
|
27
|
+
</Button>
|
|
28
|
+
</div>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useTranslations } from "next-intl";
|
|
4
|
+
import { DialogDescription, DialogHeader, DialogTitle } from "../../shadcnui";
|
|
5
|
+
|
|
6
|
+
type CommonEditorHeaderProps = {
|
|
7
|
+
type: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function CommonEditorHeader({ type, name }: CommonEditorHeaderProps) {
|
|
12
|
+
const t = useTranslations();
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<DialogHeader>
|
|
16
|
+
<DialogTitle>
|
|
17
|
+
{name
|
|
18
|
+
? t(`generic.edit.update.title`, {
|
|
19
|
+
type: type,
|
|
20
|
+
})
|
|
21
|
+
: t(`generic.edit.create.title`, { type: type })}
|
|
22
|
+
</DialogTitle>
|
|
23
|
+
<DialogDescription>
|
|
24
|
+
{name
|
|
25
|
+
? t(`generic.edit.update.description`, {
|
|
26
|
+
type: type,
|
|
27
|
+
name: name,
|
|
28
|
+
})
|
|
29
|
+
: t(`generic.edit.create.description`, {
|
|
30
|
+
type: type,
|
|
31
|
+
})}
|
|
32
|
+
</DialogDescription>
|
|
33
|
+
</DialogHeader>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { PencilIcon } from "lucide-react";
|
|
4
|
+
|
|
5
|
+
import { useTranslations } from "next-intl";
|
|
6
|
+
import { Button, DialogTrigger } from "../../shadcnui";
|
|
7
|
+
|
|
8
|
+
type CommonEditorTriggerProps = { isEdit: boolean; edit?: string; create?: string };
|
|
9
|
+
|
|
10
|
+
export function CommonEditorTrigger({ isEdit, edit, create }: CommonEditorTriggerProps) {
|
|
11
|
+
const t = useTranslations();
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<DialogTrigger asChild>
|
|
15
|
+
{isEdit ? (
|
|
16
|
+
<Button size="sm" variant={`ghost`} className="text-muted-foreground">
|
|
17
|
+
<PencilIcon />
|
|
18
|
+
</Button>
|
|
19
|
+
) : (
|
|
20
|
+
<Button size="sm" variant={`outline`}>
|
|
21
|
+
{create ? create : t(`generic.buttons.create`)}
|
|
22
|
+
</Button>
|
|
23
|
+
)}
|
|
24
|
+
</DialogTrigger>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { isValid, parse } from "date-fns";
|
|
4
|
+
import { Calendar as CalendarIcon, CircleXIcon } from "lucide-react";
|
|
5
|
+
import { ReactNode, useMemo, useState } from "react";
|
|
6
|
+
import { useI18nDateFnsLocale, useI18nLocale } from "../../i18n";
|
|
7
|
+
import {
|
|
8
|
+
Calendar,
|
|
9
|
+
Input,
|
|
10
|
+
Popover,
|
|
11
|
+
PopoverContent,
|
|
12
|
+
PopoverTrigger,
|
|
13
|
+
Select,
|
|
14
|
+
SelectContent,
|
|
15
|
+
SelectItem,
|
|
16
|
+
SelectTrigger,
|
|
17
|
+
SelectValue,
|
|
18
|
+
} from "../../shadcnui";
|
|
19
|
+
import { cn } from "../../utils";
|
|
20
|
+
|
|
21
|
+
type DatePickerPopoverProps = {
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
value?: Date;
|
|
24
|
+
onSelect: (date?: Date) => void;
|
|
25
|
+
minDate?: Date;
|
|
26
|
+
align?: "start" | "center" | "end";
|
|
27
|
+
className?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const DatePickerPopover = ({
|
|
31
|
+
children,
|
|
32
|
+
value,
|
|
33
|
+
onSelect,
|
|
34
|
+
minDate,
|
|
35
|
+
align = "start",
|
|
36
|
+
className,
|
|
37
|
+
}: DatePickerPopoverProps) => {
|
|
38
|
+
const locale = useI18nLocale();
|
|
39
|
+
const dateFnsLocale = useI18nDateFnsLocale();
|
|
40
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
41
|
+
const [displayMonth, setDisplayMonth] = useState<Date>(() => value || new Date());
|
|
42
|
+
|
|
43
|
+
// Locale-aware date formatter
|
|
44
|
+
const dateFormatter = useMemo(
|
|
45
|
+
() => new Intl.DateTimeFormat(locale, { day: "2-digit", month: "2-digit", year: "numeric" }),
|
|
46
|
+
[locale],
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// Format date for display
|
|
50
|
+
const formatDate = (date: Date): string => dateFormatter.format(date);
|
|
51
|
+
|
|
52
|
+
// Get placeholder based on locale format
|
|
53
|
+
const datePlaceholder = useMemo(() => {
|
|
54
|
+
const parts = dateFormatter.formatToParts(new Date(2000, 0, 1));
|
|
55
|
+
return parts
|
|
56
|
+
.map((part) => {
|
|
57
|
+
if (part.type === "day") return "dd";
|
|
58
|
+
if (part.type === "month") return "mm";
|
|
59
|
+
if (part.type === "year") return "yyyy";
|
|
60
|
+
return part.value;
|
|
61
|
+
})
|
|
62
|
+
.join("");
|
|
63
|
+
}, [dateFormatter]);
|
|
64
|
+
|
|
65
|
+
// Get date-fns format string from locale
|
|
66
|
+
const dateFormatPattern = useMemo(() => {
|
|
67
|
+
const parts = dateFormatter.formatToParts(new Date(2000, 0, 1));
|
|
68
|
+
return parts
|
|
69
|
+
.map((part) => {
|
|
70
|
+
if (part.type === "day") return "dd";
|
|
71
|
+
if (part.type === "month") return "MM";
|
|
72
|
+
if (part.type === "year") return "yyyy";
|
|
73
|
+
return part.value;
|
|
74
|
+
})
|
|
75
|
+
.join("");
|
|
76
|
+
}, [dateFormatter]);
|
|
77
|
+
|
|
78
|
+
const [inputValue, setInputValue] = useState<string>(() => (value ? formatDate(value) : ""));
|
|
79
|
+
|
|
80
|
+
// Generate year options (1900 to current year + 10)
|
|
81
|
+
const currentYear = new Date().getFullYear();
|
|
82
|
+
const yearOptions = Array.from({ length: currentYear - 1900 + 11 }, (_, i) => 1900 + i);
|
|
83
|
+
|
|
84
|
+
// Generate month names dynamically based on current locale
|
|
85
|
+
const monthNames = useMemo(() => {
|
|
86
|
+
const formatter = new Intl.DateTimeFormat(locale, { month: "long" });
|
|
87
|
+
return Array.from({ length: 12 }, (_, i) => {
|
|
88
|
+
const monthName = formatter.format(new Date(2000, i, 1));
|
|
89
|
+
return monthName.charAt(0).toUpperCase() + monthName.slice(1);
|
|
90
|
+
});
|
|
91
|
+
}, [locale]);
|
|
92
|
+
|
|
93
|
+
// Handle text input change
|
|
94
|
+
const handleInputChange = (inputValue: string) => {
|
|
95
|
+
setInputValue(inputValue);
|
|
96
|
+
|
|
97
|
+
// Try to parse the date using locale format
|
|
98
|
+
const parsedDate = parse(inputValue, dateFormatPattern, new Date());
|
|
99
|
+
|
|
100
|
+
if (isValid(parsedDate)) {
|
|
101
|
+
onSelect(parsedDate);
|
|
102
|
+
setDisplayMonth(parsedDate);
|
|
103
|
+
} else if (inputValue === "") {
|
|
104
|
+
onSelect(undefined);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// Handle calendar selection
|
|
109
|
+
const handleCalendarSelect = (selectedDate: Date | undefined) => {
|
|
110
|
+
onSelect(selectedDate);
|
|
111
|
+
if (selectedDate) {
|
|
112
|
+
setInputValue(formatDate(selectedDate));
|
|
113
|
+
setDisplayMonth(selectedDate);
|
|
114
|
+
} else {
|
|
115
|
+
setInputValue("");
|
|
116
|
+
}
|
|
117
|
+
setIsOpen(false);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// Handle clear button
|
|
121
|
+
const handleClear = (e: React.MouseEvent) => {
|
|
122
|
+
e.stopPropagation();
|
|
123
|
+
onSelect(undefined);
|
|
124
|
+
setInputValue("");
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<Popover open={isOpen} onOpenChange={setIsOpen}>
|
|
129
|
+
<PopoverTrigger asChild>{children}</PopoverTrigger>
|
|
130
|
+
<PopoverContent className={cn("w-auto p-0", className)} align={align} onClick={(e) => e.stopPropagation()}>
|
|
131
|
+
<div className="p-3">
|
|
132
|
+
{/* Manual Input */}
|
|
133
|
+
<div className="relative mb-3">
|
|
134
|
+
<Input
|
|
135
|
+
value={inputValue}
|
|
136
|
+
onChange={(e) => handleInputChange(e.target.value)}
|
|
137
|
+
placeholder={datePlaceholder}
|
|
138
|
+
className="pr-16"
|
|
139
|
+
onClick={(e) => e.stopPropagation()}
|
|
140
|
+
/>
|
|
141
|
+
<div className="absolute right-1 top-1/2 flex -translate-y-1/2 items-center space-x-1">
|
|
142
|
+
<button
|
|
143
|
+
type="button"
|
|
144
|
+
className="flex h-8 w-8 items-center justify-center rounded-md hover:bg-muted"
|
|
145
|
+
onClick={(e) => e.stopPropagation()}
|
|
146
|
+
>
|
|
147
|
+
<CalendarIcon className="h-4 w-4 opacity-50" />
|
|
148
|
+
</button>
|
|
149
|
+
{value && (
|
|
150
|
+
<button
|
|
151
|
+
type="button"
|
|
152
|
+
className="flex h-8 w-8 items-center justify-center rounded-md hover:bg-muted"
|
|
153
|
+
onClick={handleClear}
|
|
154
|
+
>
|
|
155
|
+
<CircleXIcon className="h-4 w-4 opacity-50 hover:opacity-100" />
|
|
156
|
+
</button>
|
|
157
|
+
)}
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
{/* Year and Month Selectors */}
|
|
162
|
+
<div className="mb-3 flex gap-2">
|
|
163
|
+
<Select
|
|
164
|
+
value={displayMonth.getMonth().toString()}
|
|
165
|
+
onValueChange={(value) => {
|
|
166
|
+
const newMonth = parseInt(value);
|
|
167
|
+
const newDate = new Date(displayMonth.getFullYear(), newMonth, 1);
|
|
168
|
+
setDisplayMonth(newDate);
|
|
169
|
+
}}
|
|
170
|
+
>
|
|
171
|
+
<SelectTrigger className="w-[130px]">
|
|
172
|
+
<SelectValue />
|
|
173
|
+
</SelectTrigger>
|
|
174
|
+
<SelectContent>
|
|
175
|
+
{monthNames.map((month, index) => (
|
|
176
|
+
<SelectItem key={index} value={index.toString()}>
|
|
177
|
+
{month}
|
|
178
|
+
</SelectItem>
|
|
179
|
+
))}
|
|
180
|
+
</SelectContent>
|
|
181
|
+
</Select>
|
|
182
|
+
|
|
183
|
+
<Select
|
|
184
|
+
value={displayMonth.getFullYear().toString()}
|
|
185
|
+
onValueChange={(value) => {
|
|
186
|
+
const newYear = parseInt(value);
|
|
187
|
+
const newDate = new Date(newYear, displayMonth.getMonth(), 1);
|
|
188
|
+
setDisplayMonth(newDate);
|
|
189
|
+
}}
|
|
190
|
+
>
|
|
191
|
+
<SelectTrigger className="w-[80px]">
|
|
192
|
+
<SelectValue />
|
|
193
|
+
</SelectTrigger>
|
|
194
|
+
<SelectContent>
|
|
195
|
+
{yearOptions.reverse().map((year) => (
|
|
196
|
+
<SelectItem key={year} value={year.toString()}>
|
|
197
|
+
{year}
|
|
198
|
+
</SelectItem>
|
|
199
|
+
))}
|
|
200
|
+
</SelectContent>
|
|
201
|
+
</Select>
|
|
202
|
+
</div>
|
|
203
|
+
|
|
204
|
+
{/* Calendar */}
|
|
205
|
+
<Calendar
|
|
206
|
+
mode="single"
|
|
207
|
+
selected={value}
|
|
208
|
+
onSelect={handleCalendarSelect}
|
|
209
|
+
disabled={(date) => (minDate && date < minDate ? true : false)}
|
|
210
|
+
locale={dateFnsLocale}
|
|
211
|
+
weekStartsOn={1}
|
|
212
|
+
month={displayMonth}
|
|
213
|
+
onMonthChange={setDisplayMonth}
|
|
214
|
+
/>
|
|
215
|
+
</div>
|
|
216
|
+
</PopoverContent>
|
|
217
|
+
</Popover>
|
|
218
|
+
);
|
|
219
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { format } from "date-fns";
|
|
4
|
+
import { CalendarIcon } from "lucide-react";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { DateRange } from "react-day-picker";
|
|
7
|
+
import { Button, Calendar, Popover, PopoverContent, PopoverTrigger } from "../../shadcnui";
|
|
8
|
+
import { cn } from "../../utils";
|
|
9
|
+
|
|
10
|
+
type DateRangeSelectorProps = {
|
|
11
|
+
onDateChange: (date?: DateRange) => void;
|
|
12
|
+
avoidSettingDates?: boolean;
|
|
13
|
+
showPreviousMonth?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function DateRangeSelector({ onDateChange, avoidSettingDates, showPreviousMonth }: DateRangeSelectorProps) {
|
|
17
|
+
const [date, setDate] = useState<DateRange | undefined>(
|
|
18
|
+
avoidSettingDates
|
|
19
|
+
? undefined
|
|
20
|
+
: {
|
|
21
|
+
from: new Date(new Date().getFullYear(), new Date().getMonth(), 1),
|
|
22
|
+
to: new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0),
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const [open, setOpen] = useState(false);
|
|
27
|
+
|
|
28
|
+
const [prevRange, setPrevRange] = useState<DateRange | undefined>(date);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (
|
|
31
|
+
date?.from &&
|
|
32
|
+
date?.to &&
|
|
33
|
+
date.to > date.from &&
|
|
34
|
+
(prevRange?.from?.getTime() !== date.from.getTime() || prevRange?.to?.getTime() !== date.to.getTime())
|
|
35
|
+
) {
|
|
36
|
+
onDateChange(date);
|
|
37
|
+
setPrevRange(date);
|
|
38
|
+
setOpen(false);
|
|
39
|
+
}
|
|
40
|
+
}, [date, prevRange, onDateChange]);
|
|
41
|
+
|
|
42
|
+
// Custom handler to reset end date if a new start date is picked
|
|
43
|
+
const handleSelect = (range: DateRange | undefined) => {
|
|
44
|
+
if (!range) {
|
|
45
|
+
setDate(undefined);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// If a new start date is picked, reset end date
|
|
49
|
+
if (range.from && (!date?.from || range.from.getTime() !== date.from.getTime())) {
|
|
50
|
+
setDate({ from: range.from, to: undefined });
|
|
51
|
+
} else {
|
|
52
|
+
setDate(range);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div className={cn("grid gap-2")}>
|
|
58
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
59
|
+
<PopoverTrigger asChild>
|
|
60
|
+
<Button
|
|
61
|
+
id="date"
|
|
62
|
+
variant={"outline"}
|
|
63
|
+
className={cn("w-[300px] justify-start text-left font-normal", !date && "text-muted-foreground")}
|
|
64
|
+
>
|
|
65
|
+
<CalendarIcon />
|
|
66
|
+
{date?.from ? (
|
|
67
|
+
date.to ? (
|
|
68
|
+
<>
|
|
69
|
+
{format(date.from, "LLL dd, y")} - {format(date.to, "LLL dd, y")}
|
|
70
|
+
</>
|
|
71
|
+
) : (
|
|
72
|
+
format(date.from, "LLL dd, y")
|
|
73
|
+
)
|
|
74
|
+
) : (
|
|
75
|
+
<span>Pick a date</span>
|
|
76
|
+
)}
|
|
77
|
+
</Button>
|
|
78
|
+
</PopoverTrigger>
|
|
79
|
+
<PopoverContent className="w-auto p-0" align="start">
|
|
80
|
+
<div className="flex flex-col gap-2 p-2">
|
|
81
|
+
<Calendar
|
|
82
|
+
mode="range"
|
|
83
|
+
defaultMonth={
|
|
84
|
+
date?.from ??
|
|
85
|
+
(showPreviousMonth ? new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1) : undefined)
|
|
86
|
+
}
|
|
87
|
+
selected={date}
|
|
88
|
+
onSelect={handleSelect}
|
|
89
|
+
numberOfMonths={2}
|
|
90
|
+
/>
|
|
91
|
+
<Button
|
|
92
|
+
variant="secondary"
|
|
93
|
+
type="button"
|
|
94
|
+
onClick={() => {
|
|
95
|
+
setDate(undefined);
|
|
96
|
+
setPrevRange(undefined);
|
|
97
|
+
onDateChange(undefined);
|
|
98
|
+
setOpen(false);
|
|
99
|
+
}}
|
|
100
|
+
className="cursor-pointer"
|
|
101
|
+
disabled={!date}
|
|
102
|
+
>
|
|
103
|
+
Clear
|
|
104
|
+
</Button>
|
|
105
|
+
</div>
|
|
106
|
+
</PopoverContent>
|
|
107
|
+
</Popover>
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|