warqadui 0.0.89 → 0.0.91

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/index.d.mts CHANGED
@@ -371,6 +371,62 @@ declare const Textarea: <T extends FieldValues>(props: TextareaProps<T> & {
371
371
  ref?: React.ForwardedRef<HTMLTextAreaElement>;
372
372
  }) => React.ReactElement;
373
373
 
374
+ declare const Enums: {
375
+ roles: readonly ["admin", "staff"];
376
+ sex: readonly ["male", "female"];
377
+ accountTypes: readonly ["employee", "supplier", "customer", "amaanah"];
378
+ verificationTypes: readonly ["email_verification", "password_reset"];
379
+ auditActions: readonly ["create", "update", "delete", "login", "logout"];
380
+ walletTypes: readonly ["bank", "cash", "mobile"];
381
+ currencies: readonly ["USD", "TZS", "KES", "CNY"];
382
+ };
383
+
384
+ interface ThemeConfig {
385
+ primaryColor?: string;
386
+ inputHeight?: string;
387
+ }
388
+ interface StoreConfig {
389
+ name?: string;
390
+ address?: string;
391
+ phone?: string;
392
+ email?: string;
393
+ logo?: string;
394
+ }
395
+ type EnumsConfig = {
396
+ [K in keyof typeof Enums]: string[] | readonly string[];
397
+ };
398
+ interface WarqadConfig {
399
+ api?: string;
400
+ theme?: ThemeConfig;
401
+ store?: StoreConfig;
402
+ enums?: Partial<EnumsConfig>;
403
+ }
404
+ interface WarqadConfigContextType {
405
+ config: WarqadConfig & {
406
+ theme: Required<ThemeConfig>;
407
+ store: Required<StoreConfig>;
408
+ enums: EnumsConfig;
409
+ };
410
+ }
411
+ /**
412
+ * Hook to access the current Warqad configuration.
413
+ */
414
+ declare const useWarqadConfig: () => WarqadConfig & {
415
+ theme: Required<ThemeConfig>;
416
+ store: Required<StoreConfig>;
417
+ enums: EnumsConfig;
418
+ };
419
+ interface WarqadProviderProps {
420
+ children: ReactNode;
421
+ config?: WarqadConfig;
422
+ }
423
+ /**
424
+ * WarqadProvider
425
+ *
426
+ * Provides configuration and theme values to the entire application.
427
+ */
428
+ declare const WarqadProvider: ({ children, config }: WarqadProviderProps) => react_jsx_runtime.JSX.Element;
429
+
374
430
  interface Option {
375
431
  value: string | number | boolean;
376
432
  label: string;
@@ -388,6 +444,8 @@ interface SelectProps extends Omit<React__default.SelectHTMLAttributes<HTMLSelec
388
444
  value?: any;
389
445
  variant?: "ghost" | "default";
390
446
  children?: ReactNode;
447
+ enum?: string[] | readonly string[];
448
+ enumName?: keyof EnumsConfig;
391
449
  }
392
450
  interface SelectContextValue {
393
451
  isOpen: boolean;
@@ -850,40 +908,6 @@ declare const useTransaction: ({ url, v, delay, params, dateFilter, }: {
850
908
  date: String | null | undefined;
851
909
  };
852
910
 
853
- interface ThemeConfig {
854
- primaryColor?: string;
855
- inputHeight?: string;
856
- }
857
- interface StoreConfig {
858
- name?: string;
859
- address?: string;
860
- phone?: string;
861
- email?: string;
862
- logo?: string;
863
- }
864
- interface WarqadConfig {
865
- api?: string;
866
- theme?: ThemeConfig;
867
- store?: StoreConfig;
868
- }
869
- interface WarqadConfigContextType {
870
- config: WarqadConfig;
871
- }
872
- /**
873
- * Hook to access the current Warqad configuration.
874
- */
875
- declare const useWarqadConfig: () => WarqadConfig;
876
- interface WarqadProviderProps {
877
- children: ReactNode;
878
- config?: WarqadConfig;
879
- }
880
- /**
881
- * WarqadProvider
882
- *
883
- * Provides configuration and theme values to the entire application.
884
- */
885
- declare const WarqadProvider: ({ children, config }: WarqadProviderProps) => react_jsx_runtime.JSX.Element;
886
-
887
911
  interface PdfOptions {
888
912
  orientation?: "portrait" | "landscape";
889
913
  unit?: "mm" | "cm" | "in" | "px";
@@ -1381,13 +1405,13 @@ declare const createWalletSchema: z$1.ZodObject<{
1381
1405
  branch: z$1.ZodOptional<z$1.ZodString>;
1382
1406
  }, "strip", z$1.ZodTypeAny, {
1383
1407
  name: string;
1384
- type: "mobile" | "bank" | "cash";
1408
+ type: "bank" | "cash" | "mobile";
1385
1409
  currency: "USD" | "TZS" | "KES" | "CNY";
1386
1410
  branch?: string | undefined;
1387
1411
  accountNo?: string | undefined;
1388
1412
  }, {
1389
1413
  name: string;
1390
- type: "mobile" | "bank" | "cash";
1414
+ type: "bank" | "cash" | "mobile";
1391
1415
  currency: "USD" | "TZS" | "KES" | "CNY";
1392
1416
  branch?: string | undefined;
1393
1417
  accountNo?: string | undefined;
@@ -1414,4 +1438,4 @@ declare const ErrorPage: (({ title, message, statusCode, action, className, }: E
1414
1438
  400: (props: ErrorPageProps) => react_jsx_runtime.JSX.Element;
1415
1439
  };
1416
1440
 
1417
- export { AccountFields, AccountForm, type AccountType, Accounts, AdminProtectedRoute, Badge, type BadgeProps, type BranchesContext, Branding, type BrandingProps, Breadcrumbs, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CategoryCard, type CategoryItem, ClassicSpin, CodeBlock, ConfirmModal, type ConfirmModalProps, type CreateAccountSchemaType, type CreateWalletSchemaType, DashboardLayout, DataTable, type DataTableColumn, DateInput, type DateInputProps, type DeleteFunction, Dropdown, type DropdownItem, type DropdownProps, ErrorPage, type ErrorPageProps, type FetchFunction, type FetchProps, Fields, Guard, InfoGrid, Input, type InputProps, LinkUser, LoadingBox, LoadingSpin, type LoginSchema, type LoginTheme, Modal, type ModalProps, type NavItem, type NavItems, type Option, OverlaySpin, PageA4, PageHeader, type PdfOptions, PhoneInput, type PhoneInputProps, type PostFunction, PostTable, type PostTableActions, type PostTableChangeParams, ProfileCard, type ProfileCardProps, ProfileDropdown, type ProfileDropdownItem, type ProfileDropdownProps, ProfilePage, ProfileView, type ProfileViewInfoItem, type ProfileViewProps, ProtectedRoute, type PutFunction, ResetPasswordPage, type Role, SearchApi, SearchApiContent, SearchApiInput, SearchApiItem, type SearchApiProps, SearchApiTrigger, Select, SelectContent, SelectItem, type SelectProps, SelectTrigger, SimpleTable, type SimpleTableColumn, type StorageManager, type StoreConfig, Textarea, type TextareaProps, type ThemeConfig, ThemeProvider, ThemeToggle, ThemedLogin, UnProtectedRoute, type UseModalReturn, UserForm, UserProfile, Users, Views, WalletField, WalletForm, Wallets, type WarqadConfig, type WarqadConfigContextType, WarqadProvider, createAccountSchema, createUserSchema, type createUserSchemaType, createWalletSchema, generatePdf, linkUserSchema, type linkUserSchemaType, resetPasswordSchema, type resetPasswordSchemaType, storage, updateUserEmailSchema, type updateUserEmailSchemaType, useA4CategoryView, useA4StatementView, useAntdImageUpload, useApi, useApp, useAuth, useAuthStore, useLogin, useModal, useSearchApiContext, useSelectContext, useTheme, useTransaction, useWarqadConfig, verifyUserEmailSchema, type verifyUserEmailSchemaType };
1441
+ export { AccountFields, AccountForm, type AccountType, Accounts, AdminProtectedRoute, Badge, type BadgeProps, type BranchesContext, Branding, type BrandingProps, Breadcrumbs, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CategoryCard, type CategoryItem, ClassicSpin, CodeBlock, ConfirmModal, type ConfirmModalProps, type CreateAccountSchemaType, type CreateWalletSchemaType, DashboardLayout, DataTable, type DataTableColumn, DateInput, type DateInputProps, type DeleteFunction, Dropdown, type DropdownItem, type DropdownProps, type EnumsConfig, ErrorPage, type ErrorPageProps, type FetchFunction, type FetchProps, Fields, Guard, InfoGrid, Input, type InputProps, LinkUser, LoadingBox, LoadingSpin, type LoginSchema, type LoginTheme, Modal, type ModalProps, type NavItem, type NavItems, type Option, OverlaySpin, PageA4, PageHeader, type PdfOptions, PhoneInput, type PhoneInputProps, type PostFunction, PostTable, type PostTableActions, type PostTableChangeParams, ProfileCard, type ProfileCardProps, ProfileDropdown, type ProfileDropdownItem, type ProfileDropdownProps, ProfilePage, ProfileView, type ProfileViewInfoItem, type ProfileViewProps, ProtectedRoute, type PutFunction, ResetPasswordPage, type Role, SearchApi, SearchApiContent, SearchApiInput, SearchApiItem, type SearchApiProps, SearchApiTrigger, Select, SelectContent, SelectItem, type SelectProps, SelectTrigger, SimpleTable, type SimpleTableColumn, type StorageManager, type StoreConfig, Textarea, type TextareaProps, type ThemeConfig, ThemeProvider, ThemeToggle, ThemedLogin, UnProtectedRoute, type UseModalReturn, UserForm, UserProfile, Users, Views, WalletField, WalletForm, Wallets, type WarqadConfig, type WarqadConfigContextType, WarqadProvider, createAccountSchema, createUserSchema, type createUserSchemaType, createWalletSchema, generatePdf, linkUserSchema, type linkUserSchemaType, resetPasswordSchema, type resetPasswordSchemaType, storage, updateUserEmailSchema, type updateUserEmailSchemaType, useA4CategoryView, useA4StatementView, useAntdImageUpload, useApi, useApp, useAuth, useAuthStore, useLogin, useModal, useSearchApiContext, useSelectContext, useTheme, useTransaction, useWarqadConfig, verifyUserEmailSchema, type verifyUserEmailSchemaType };
package/dist/index.d.ts CHANGED
@@ -371,6 +371,62 @@ declare const Textarea: <T extends FieldValues>(props: TextareaProps<T> & {
371
371
  ref?: React.ForwardedRef<HTMLTextAreaElement>;
372
372
  }) => React.ReactElement;
373
373
 
374
+ declare const Enums: {
375
+ roles: readonly ["admin", "staff"];
376
+ sex: readonly ["male", "female"];
377
+ accountTypes: readonly ["employee", "supplier", "customer", "amaanah"];
378
+ verificationTypes: readonly ["email_verification", "password_reset"];
379
+ auditActions: readonly ["create", "update", "delete", "login", "logout"];
380
+ walletTypes: readonly ["bank", "cash", "mobile"];
381
+ currencies: readonly ["USD", "TZS", "KES", "CNY"];
382
+ };
383
+
384
+ interface ThemeConfig {
385
+ primaryColor?: string;
386
+ inputHeight?: string;
387
+ }
388
+ interface StoreConfig {
389
+ name?: string;
390
+ address?: string;
391
+ phone?: string;
392
+ email?: string;
393
+ logo?: string;
394
+ }
395
+ type EnumsConfig = {
396
+ [K in keyof typeof Enums]: string[] | readonly string[];
397
+ };
398
+ interface WarqadConfig {
399
+ api?: string;
400
+ theme?: ThemeConfig;
401
+ store?: StoreConfig;
402
+ enums?: Partial<EnumsConfig>;
403
+ }
404
+ interface WarqadConfigContextType {
405
+ config: WarqadConfig & {
406
+ theme: Required<ThemeConfig>;
407
+ store: Required<StoreConfig>;
408
+ enums: EnumsConfig;
409
+ };
410
+ }
411
+ /**
412
+ * Hook to access the current Warqad configuration.
413
+ */
414
+ declare const useWarqadConfig: () => WarqadConfig & {
415
+ theme: Required<ThemeConfig>;
416
+ store: Required<StoreConfig>;
417
+ enums: EnumsConfig;
418
+ };
419
+ interface WarqadProviderProps {
420
+ children: ReactNode;
421
+ config?: WarqadConfig;
422
+ }
423
+ /**
424
+ * WarqadProvider
425
+ *
426
+ * Provides configuration and theme values to the entire application.
427
+ */
428
+ declare const WarqadProvider: ({ children, config }: WarqadProviderProps) => react_jsx_runtime.JSX.Element;
429
+
374
430
  interface Option {
375
431
  value: string | number | boolean;
376
432
  label: string;
@@ -388,6 +444,8 @@ interface SelectProps extends Omit<React__default.SelectHTMLAttributes<HTMLSelec
388
444
  value?: any;
389
445
  variant?: "ghost" | "default";
390
446
  children?: ReactNode;
447
+ enum?: string[] | readonly string[];
448
+ enumName?: keyof EnumsConfig;
391
449
  }
392
450
  interface SelectContextValue {
393
451
  isOpen: boolean;
@@ -850,40 +908,6 @@ declare const useTransaction: ({ url, v, delay, params, dateFilter, }: {
850
908
  date: String | null | undefined;
851
909
  };
852
910
 
853
- interface ThemeConfig {
854
- primaryColor?: string;
855
- inputHeight?: string;
856
- }
857
- interface StoreConfig {
858
- name?: string;
859
- address?: string;
860
- phone?: string;
861
- email?: string;
862
- logo?: string;
863
- }
864
- interface WarqadConfig {
865
- api?: string;
866
- theme?: ThemeConfig;
867
- store?: StoreConfig;
868
- }
869
- interface WarqadConfigContextType {
870
- config: WarqadConfig;
871
- }
872
- /**
873
- * Hook to access the current Warqad configuration.
874
- */
875
- declare const useWarqadConfig: () => WarqadConfig;
876
- interface WarqadProviderProps {
877
- children: ReactNode;
878
- config?: WarqadConfig;
879
- }
880
- /**
881
- * WarqadProvider
882
- *
883
- * Provides configuration and theme values to the entire application.
884
- */
885
- declare const WarqadProvider: ({ children, config }: WarqadProviderProps) => react_jsx_runtime.JSX.Element;
886
-
887
911
  interface PdfOptions {
888
912
  orientation?: "portrait" | "landscape";
889
913
  unit?: "mm" | "cm" | "in" | "px";
@@ -1381,13 +1405,13 @@ declare const createWalletSchema: z$1.ZodObject<{
1381
1405
  branch: z$1.ZodOptional<z$1.ZodString>;
1382
1406
  }, "strip", z$1.ZodTypeAny, {
1383
1407
  name: string;
1384
- type: "mobile" | "bank" | "cash";
1408
+ type: "bank" | "cash" | "mobile";
1385
1409
  currency: "USD" | "TZS" | "KES" | "CNY";
1386
1410
  branch?: string | undefined;
1387
1411
  accountNo?: string | undefined;
1388
1412
  }, {
1389
1413
  name: string;
1390
- type: "mobile" | "bank" | "cash";
1414
+ type: "bank" | "cash" | "mobile";
1391
1415
  currency: "USD" | "TZS" | "KES" | "CNY";
1392
1416
  branch?: string | undefined;
1393
1417
  accountNo?: string | undefined;
@@ -1414,4 +1438,4 @@ declare const ErrorPage: (({ title, message, statusCode, action, className, }: E
1414
1438
  400: (props: ErrorPageProps) => react_jsx_runtime.JSX.Element;
1415
1439
  };
1416
1440
 
1417
- export { AccountFields, AccountForm, type AccountType, Accounts, AdminProtectedRoute, Badge, type BadgeProps, type BranchesContext, Branding, type BrandingProps, Breadcrumbs, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CategoryCard, type CategoryItem, ClassicSpin, CodeBlock, ConfirmModal, type ConfirmModalProps, type CreateAccountSchemaType, type CreateWalletSchemaType, DashboardLayout, DataTable, type DataTableColumn, DateInput, type DateInputProps, type DeleteFunction, Dropdown, type DropdownItem, type DropdownProps, ErrorPage, type ErrorPageProps, type FetchFunction, type FetchProps, Fields, Guard, InfoGrid, Input, type InputProps, LinkUser, LoadingBox, LoadingSpin, type LoginSchema, type LoginTheme, Modal, type ModalProps, type NavItem, type NavItems, type Option, OverlaySpin, PageA4, PageHeader, type PdfOptions, PhoneInput, type PhoneInputProps, type PostFunction, PostTable, type PostTableActions, type PostTableChangeParams, ProfileCard, type ProfileCardProps, ProfileDropdown, type ProfileDropdownItem, type ProfileDropdownProps, ProfilePage, ProfileView, type ProfileViewInfoItem, type ProfileViewProps, ProtectedRoute, type PutFunction, ResetPasswordPage, type Role, SearchApi, SearchApiContent, SearchApiInput, SearchApiItem, type SearchApiProps, SearchApiTrigger, Select, SelectContent, SelectItem, type SelectProps, SelectTrigger, SimpleTable, type SimpleTableColumn, type StorageManager, type StoreConfig, Textarea, type TextareaProps, type ThemeConfig, ThemeProvider, ThemeToggle, ThemedLogin, UnProtectedRoute, type UseModalReturn, UserForm, UserProfile, Users, Views, WalletField, WalletForm, Wallets, type WarqadConfig, type WarqadConfigContextType, WarqadProvider, createAccountSchema, createUserSchema, type createUserSchemaType, createWalletSchema, generatePdf, linkUserSchema, type linkUserSchemaType, resetPasswordSchema, type resetPasswordSchemaType, storage, updateUserEmailSchema, type updateUserEmailSchemaType, useA4CategoryView, useA4StatementView, useAntdImageUpload, useApi, useApp, useAuth, useAuthStore, useLogin, useModal, useSearchApiContext, useSelectContext, useTheme, useTransaction, useWarqadConfig, verifyUserEmailSchema, type verifyUserEmailSchemaType };
1441
+ export { AccountFields, AccountForm, type AccountType, Accounts, AdminProtectedRoute, Badge, type BadgeProps, type BranchesContext, Branding, type BrandingProps, Breadcrumbs, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CategoryCard, type CategoryItem, ClassicSpin, CodeBlock, ConfirmModal, type ConfirmModalProps, type CreateAccountSchemaType, type CreateWalletSchemaType, DashboardLayout, DataTable, type DataTableColumn, DateInput, type DateInputProps, type DeleteFunction, Dropdown, type DropdownItem, type DropdownProps, type EnumsConfig, ErrorPage, type ErrorPageProps, type FetchFunction, type FetchProps, Fields, Guard, InfoGrid, Input, type InputProps, LinkUser, LoadingBox, LoadingSpin, type LoginSchema, type LoginTheme, Modal, type ModalProps, type NavItem, type NavItems, type Option, OverlaySpin, PageA4, PageHeader, type PdfOptions, PhoneInput, type PhoneInputProps, type PostFunction, PostTable, type PostTableActions, type PostTableChangeParams, ProfileCard, type ProfileCardProps, ProfileDropdown, type ProfileDropdownItem, type ProfileDropdownProps, ProfilePage, ProfileView, type ProfileViewInfoItem, type ProfileViewProps, ProtectedRoute, type PutFunction, ResetPasswordPage, type Role, SearchApi, SearchApiContent, SearchApiInput, SearchApiItem, type SearchApiProps, SearchApiTrigger, Select, SelectContent, SelectItem, type SelectProps, SelectTrigger, SimpleTable, type SimpleTableColumn, type StorageManager, type StoreConfig, Textarea, type TextareaProps, type ThemeConfig, ThemeProvider, ThemeToggle, ThemedLogin, UnProtectedRoute, type UseModalReturn, UserForm, UserProfile, Users, Views, WalletField, WalletForm, Wallets, type WarqadConfig, type WarqadConfigContextType, WarqadProvider, createAccountSchema, createUserSchema, type createUserSchemaType, createWalletSchema, generatePdf, linkUserSchema, type linkUserSchemaType, resetPasswordSchema, type resetPasswordSchemaType, storage, updateUserEmailSchema, type updateUserEmailSchemaType, useA4CategoryView, useA4StatementView, useAntdImageUpload, useApi, useApp, useAuth, useAuthStore, useLogin, useModal, useSearchApiContext, useSelectContext, useTheme, useTransaction, useWarqadConfig, verifyUserEmailSchema, type verifyUserEmailSchemaType };
package/dist/index.js CHANGED
@@ -413,6 +413,18 @@ var useTheme = () => {
413
413
  return context;
414
414
  };
415
415
 
416
+ // src/utils/Enums.ts
417
+ var Enums = {
418
+ roles: ["admin", "staff"],
419
+ sex: ["male", "female"],
420
+ accountTypes: ["employee", "supplier", "customer", "amaanah"],
421
+ verificationTypes: ["email_verification", "password_reset"],
422
+ auditActions: ["create", "update", "delete", "login", "logout"],
423
+ walletTypes: ["bank", "cash", "mobile"],
424
+ currencies: ["USD", "TZS", "KES", "CNY"]
425
+ };
426
+ var Enums_default = Enums;
427
+
416
428
  // src/providers/WarqadProvider.tsx
417
429
  var import_jsx_runtime5 = require("react/jsx-runtime");
418
430
  var WarqadConfigContext = (0, import_react3.createContext)(
@@ -448,6 +460,10 @@ var WarqadProvider = ({ children, config }) => {
448
460
  store: {
449
461
  ...DEFAULT_STORE,
450
462
  ...config?.store
463
+ },
464
+ enums: {
465
+ ...Enums_default,
466
+ ...config?.enums
451
467
  }
452
468
  }),
453
469
  [config]
@@ -1924,7 +1940,28 @@ var useSelectContext = () => {
1924
1940
  return context;
1925
1941
  };
1926
1942
  var Select = (0, import_react14.forwardRef)((props, ref) => {
1927
- const { form, name, onChange, value, children, options = [] } = props;
1943
+ const { enums } = useWarqadConfig();
1944
+ const {
1945
+ form,
1946
+ name,
1947
+ onChange,
1948
+ value,
1949
+ children,
1950
+ options: initialOptions = [],
1951
+ enum: enumData,
1952
+ enumName
1953
+ } = props;
1954
+ const options = (0, import_react14.useMemo)(() => {
1955
+ if (initialOptions.length > 0) return initialOptions;
1956
+ const targetEnum = enumData || (enumName ? enums[enumName] : void 0);
1957
+ if (targetEnum) {
1958
+ return targetEnum.map((val) => ({
1959
+ value: val,
1960
+ label: String(val).charAt(0).toUpperCase() + String(val).slice(1)
1961
+ }));
1962
+ }
1963
+ return [];
1964
+ }, [initialOptions, enumData, enumName, enums]);
1928
1965
  (0, import_react14.useEffect)(() => {
1929
1966
  if (form && name && value !== void 0 && value !== null && value !== "") {
1930
1967
  const currentFormValue = form.getValues(name);
@@ -8088,8 +8125,14 @@ var import_react34 = require("react");
8088
8125
  var import_antd6 = require("antd");
8089
8126
  var import_jsx_runtime43 = require("react/jsx-runtime");
8090
8127
  function Accounts({ v, url }) {
8128
+ const { enums } = useWarqadConfig();
8091
8129
  const { branchId } = (0, import_react_router_dom6.useParams)();
8130
+ const navigate = (0, import_react_router_dom6.useNavigate)();
8092
8131
  const { type } = (0, import_react_router_dom6.useParams)();
8132
+ if (!enums.accountTypes.includes(type)) {
8133
+ import_antd6.message.error("Invalid account type");
8134
+ return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(import_react_router_dom6.Navigate, { to: "/accounts", replace: true });
8135
+ }
8093
8136
  const [deleteAccount, setDeleteAccount] = (0, import_react34.useState)(null);
8094
8137
  const { isLoading, remove } = useApis_default();
8095
8138
  const isEmployee = type === "employee";
@@ -8099,7 +8142,6 @@ function Accounts({ v, url }) {
8099
8142
  dateFilter: false
8100
8143
  });
8101
8144
  const { Modal: Modal2 } = useModal();
8102
- const navigate = (0, import_react_router_dom6.useNavigate)();
8103
8145
  const items = (data2) => [
8104
8146
  {
8105
8147
  label: `Edit ${type}`,
@@ -8242,18 +8284,6 @@ var useApp = () => {
8242
8284
  };
8243
8285
  var useApp_default = useApp;
8244
8286
 
8245
- // src/utils/Enums.ts
8246
- var Enums = {
8247
- roles: ["admin", "staff"],
8248
- sex: ["male", "female"],
8249
- accountTypes: ["employee", "supplier", "customer", "investor"],
8250
- verificationTypes: ["email_verification", "password_reset"],
8251
- auditActions: ["create", "update", "delete", "login", "logout"],
8252
- walletTypes: ["bank", "cash", "mobile"],
8253
- currencies: ["USD", "TZS", "KES", "CNY"]
8254
- };
8255
- var Enums_default = Enums;
8256
-
8257
8287
  // src/components/accounts/schema.tsx
8258
8288
  var import_zod2 = require("zod");
8259
8289
  var createAccountSchema = import_zod2.z.object({
@@ -8518,11 +8548,16 @@ var Feilds_default = AccountFields;
8518
8548
  var import_react_router_dom9 = require("react-router-dom");
8519
8549
  var import_jsx_runtime49 = require("react/jsx-runtime");
8520
8550
  function AccountForm() {
8551
+ const { enums } = useWarqadConfig();
8521
8552
  const { branchId } = (0, import_react_router_dom9.useParams)();
8522
8553
  const { getQuery, getParams, navigate } = useApp_default();
8523
8554
  const id = getQuery("id");
8524
8555
  const type = getParams("type");
8525
8556
  const isEdit = !!id;
8557
+ if (!enums.accountTypes.includes(type)) {
8558
+ import_antd7.message.error("Invalid account type");
8559
+ return /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(import_react_router_dom9.Navigate, { to: "/accounts", replace: true });
8560
+ }
8526
8561
  const { post, put, isLoading } = useApis_default();
8527
8562
  const { isLoading: isLoadingGet, get } = useApis_default();
8528
8563
  const methods = (0, import_react_hook_form8.useForm)({
@@ -8610,10 +8645,7 @@ function AccountForm() {
8610
8645
  label: "Sex",
8611
8646
  form: methods,
8612
8647
  name: "sex",
8613
- options: Enums_default.sex.map((sex) => ({
8614
- value: sex,
8615
- label: sex
8616
- }))
8648
+ enumName: "sex"
8617
8649
  }
8618
8650
  ),
8619
8651
  /* @__PURE__ */ (0, import_jsx_runtime49.jsx)(
@@ -9899,6 +9931,7 @@ var import_react44 = require("react");
9899
9931
  var import_react_router_dom15 = require("react-router-dom");
9900
9932
  var import_jsx_runtime61 = require("react/jsx-runtime");
9901
9933
  function WalletForm() {
9934
+ const { enums } = useWarqadConfig();
9902
9935
  const { branchId } = (0, import_react_router_dom15.useParams)();
9903
9936
  const { getQuery, navigate } = useApp_default();
9904
9937
  const id = getQuery("id");
@@ -9993,10 +10026,7 @@ function WalletForm() {
9993
10026
  form: methods,
9994
10027
  required: true,
9995
10028
  name: "type",
9996
- options: Enums_default.walletTypes.map((type) => ({
9997
- value: type,
9998
- label: type
9999
- }))
10029
+ enumName: "walletTypes"
10000
10030
  }
10001
10031
  ),
10002
10032
  /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
@@ -10006,10 +10036,7 @@ function WalletForm() {
10006
10036
  form: methods,
10007
10037
  name: "currency",
10008
10038
  required: true,
10009
- options: Enums_default.currencies.map((currency) => ({
10010
- value: currency,
10011
- label: currency
10012
- }))
10039
+ enumName: "currencies"
10013
10040
  }
10014
10041
  ),
10015
10042
  /* @__PURE__ */ (0, import_jsx_runtime61.jsx)(
package/dist/index.mjs CHANGED
@@ -295,6 +295,18 @@ var useTheme = () => {
295
295
  return context;
296
296
  };
297
297
 
298
+ // src/utils/Enums.ts
299
+ var Enums = {
300
+ roles: ["admin", "staff"],
301
+ sex: ["male", "female"],
302
+ accountTypes: ["employee", "supplier", "customer", "amaanah"],
303
+ verificationTypes: ["email_verification", "password_reset"],
304
+ auditActions: ["create", "update", "delete", "login", "logout"],
305
+ walletTypes: ["bank", "cash", "mobile"],
306
+ currencies: ["USD", "TZS", "KES", "CNY"]
307
+ };
308
+ var Enums_default = Enums;
309
+
298
310
  // src/providers/WarqadProvider.tsx
299
311
  import { jsx as jsx5 } from "react/jsx-runtime";
300
312
  var WarqadConfigContext = createContext2(
@@ -330,6 +342,10 @@ var WarqadProvider = ({ children, config }) => {
330
342
  store: {
331
343
  ...DEFAULT_STORE,
332
344
  ...config?.store
345
+ },
346
+ enums: {
347
+ ...Enums_default,
348
+ ...config?.enums
333
349
  }
334
350
  }),
335
351
  [config]
@@ -1803,7 +1819,8 @@ import React8, {
1803
1819
  useState as useState13,
1804
1820
  useRef as useRef3,
1805
1821
  useEffect as useEffect8,
1806
- forwardRef as forwardRef3
1822
+ forwardRef as forwardRef3,
1823
+ useMemo as useMemo4
1807
1824
  } from "react";
1808
1825
  import { createPortal as createPortal2 } from "react-dom";
1809
1826
  import { ChevronDown as ChevronDown2, Check as Check2 } from "lucide-react";
@@ -1817,7 +1834,28 @@ var useSelectContext = () => {
1817
1834
  return context;
1818
1835
  };
1819
1836
  var Select = forwardRef3((props, ref) => {
1820
- const { form, name, onChange, value, children, options = [] } = props;
1837
+ const { enums } = useWarqadConfig();
1838
+ const {
1839
+ form,
1840
+ name,
1841
+ onChange,
1842
+ value,
1843
+ children,
1844
+ options: initialOptions = [],
1845
+ enum: enumData,
1846
+ enumName
1847
+ } = props;
1848
+ const options = useMemo4(() => {
1849
+ if (initialOptions.length > 0) return initialOptions;
1850
+ const targetEnum = enumData || (enumName ? enums[enumName] : void 0);
1851
+ if (targetEnum) {
1852
+ return targetEnum.map((val) => ({
1853
+ value: val,
1854
+ label: String(val).charAt(0).toUpperCase() + String(val).slice(1)
1855
+ }));
1856
+ }
1857
+ return [];
1858
+ }, [initialOptions, enumData, enumName, enums]);
1821
1859
  useEffect8(() => {
1822
1860
  if (form && name && value !== void 0 && value !== null && value !== "") {
1823
1861
  const currentFormValue = form.getValues(name);
@@ -3134,7 +3172,7 @@ var Fields = {
3134
3172
  var Fields_default = Fields;
3135
3173
 
3136
3174
  // src/components/tables/DataTable.tsx
3137
- import React10, { useState as useState17, useMemo as useMemo4, useEffect as useEffect11 } from "react";
3175
+ import React10, { useState as useState17, useMemo as useMemo5, useEffect as useEffect11 } from "react";
3138
3176
  import {
3139
3177
  useReactTable,
3140
3178
  getCoreRowModel,
@@ -3205,7 +3243,7 @@ function DataTable({
3205
3243
  }
3206
3244
  return initialState;
3207
3245
  });
3208
- const columns = useMemo4(() => {
3246
+ const columns = useMemo5(() => {
3209
3247
  let mappedColumns = userColumns.map((col) => ({
3210
3248
  ...col,
3211
3249
  accessorKey: col.key || col.accessorKey,
@@ -3455,7 +3493,7 @@ function DataTable({
3455
3493
  // src/components/tables/PostTable.tsx
3456
3494
  import React11, {
3457
3495
  useState as useState18,
3458
- useMemo as useMemo5,
3496
+ useMemo as useMemo6,
3459
3497
  useEffect as useEffect12,
3460
3498
  useRef as useRef5,
3461
3499
  useCallback as useCallback3
@@ -3791,7 +3829,7 @@ function PostTable({
3791
3829
  },
3792
3830
  [handleCancelEdit]
3793
3831
  );
3794
- const actionColumn = useMemo5(
3832
+ const actionColumn = useMemo6(
3795
3833
  () => ({
3796
3834
  id: "actions",
3797
3835
  header: "Actions",
@@ -3823,7 +3861,7 @@ function PostTable({
3823
3861
  }),
3824
3862
  []
3825
3863
  );
3826
- const columns = useMemo5(() => {
3864
+ const columns = useMemo6(() => {
3827
3865
  const mappedUserColumns = userColumns.map((col) => ({
3828
3866
  ...col,
3829
3867
  accessorKey: col.key || col.accessorKey,
@@ -4161,7 +4199,7 @@ function PostTable({
4161
4199
  }
4162
4200
 
4163
4201
  // src/components/tables/SimpleTable.tsx
4164
- import { useMemo as useMemo6 } from "react";
4202
+ import { useMemo as useMemo7 } from "react";
4165
4203
  import {
4166
4204
  useReactTable as useReactTable3,
4167
4205
  getCoreRowModel as getCoreRowModel3,
@@ -4183,7 +4221,7 @@ function SimpleTable({
4183
4221
  emptyState,
4184
4222
  skeletonCount = 5
4185
4223
  }) {
4186
- const columns = useMemo6(() => {
4224
+ const columns = useMemo7(() => {
4187
4225
  const cols = userColumns.filter((col) => !col.hide).map((col) => ({
4188
4226
  ...col,
4189
4227
  accessorKey: col.key || col.accessorKey,
@@ -4209,7 +4247,7 @@ function SimpleTable({
4209
4247
  columns,
4210
4248
  getCoreRowModel: getCoreRowModel3()
4211
4249
  });
4212
- const hasFooters = useMemo6(() => {
4250
+ const hasFooters = useMemo7(() => {
4213
4251
  return table.getFooterGroups().some(
4214
4252
  (group) => group.headers.some(
4215
4253
  (header) => !header.isPlaceholder && header.column.columnDef.footer
@@ -6086,7 +6124,7 @@ var useA4CategoryView = ({
6086
6124
  var useA4CategoryView_default = useA4CategoryView;
6087
6125
 
6088
6126
  // src/hooks/Fetches/useTransaction.tsx
6089
- import { useEffect as useEffect16, useState as useState24, useMemo as useMemo7, useCallback as useCallback4 } from "react";
6127
+ import { useEffect as useEffect16, useState as useState24, useMemo as useMemo8, useCallback as useCallback4 } from "react";
6090
6128
  import { AlertCircle as AlertCircle4, FileX as FileX3, Plus as Plus2, RefreshCw as RefreshCw3 } from "lucide-react";
6091
6129
  import moment from "moment";
6092
6130
  import { jsx as jsx38, jsxs as jsxs30 } from "react/jsx-runtime";
@@ -6117,7 +6155,7 @@ var useTransaction = ({
6117
6155
  useEffect16(() => {
6118
6156
  getData();
6119
6157
  }, [url, v, JSON.stringify(params), delay, date]);
6120
- const TransactionViewComponent = useMemo7(() => {
6158
+ const TransactionViewComponent = useMemo8(() => {
6121
6159
  return ({
6122
6160
  columns = [
6123
6161
  {
@@ -8042,14 +8080,20 @@ var AdminProtectedRoute = () => {
8042
8080
  };
8043
8081
 
8044
8082
  // src/components/accounts/Accounts.tsx
8045
- import { useNavigate as useNavigate4, useParams } from "react-router-dom";
8083
+ import { Navigate as Navigate2, useNavigate as useNavigate4, useParams } from "react-router-dom";
8046
8084
  import { Cable, EllipsisVertical, FilePenLine, Trash2 as Trash22 } from "lucide-react";
8047
8085
  import { useState as useState26 } from "react";
8048
8086
  import { message as message4 } from "antd";
8049
8087
  import { Fragment as Fragment9, jsx as jsx43, jsxs as jsxs33 } from "react/jsx-runtime";
8050
8088
  function Accounts({ v, url }) {
8089
+ const { enums } = useWarqadConfig();
8051
8090
  const { branchId } = useParams();
8091
+ const navigate = useNavigate4();
8052
8092
  const { type } = useParams();
8093
+ if (!enums.accountTypes.includes(type)) {
8094
+ message4.error("Invalid account type");
8095
+ return /* @__PURE__ */ jsx43(Navigate2, { to: "/accounts", replace: true });
8096
+ }
8053
8097
  const [deleteAccount, setDeleteAccount] = useState26(null);
8054
8098
  const { isLoading, remove } = useApis_default();
8055
8099
  const isEmployee = type === "employee";
@@ -8059,7 +8103,6 @@ function Accounts({ v, url }) {
8059
8103
  dateFilter: false
8060
8104
  });
8061
8105
  const { Modal: Modal2 } = useModal();
8062
- const navigate = useNavigate4();
8063
8106
  const items = (data2) => [
8064
8107
  {
8065
8108
  label: `Edit ${type}`,
@@ -8202,18 +8245,6 @@ var useApp = () => {
8202
8245
  };
8203
8246
  var useApp_default = useApp;
8204
8247
 
8205
- // src/utils/Enums.ts
8206
- var Enums = {
8207
- roles: ["admin", "staff"],
8208
- sex: ["male", "female"],
8209
- accountTypes: ["employee", "supplier", "customer", "investor"],
8210
- verificationTypes: ["email_verification", "password_reset"],
8211
- auditActions: ["create", "update", "delete", "login", "logout"],
8212
- walletTypes: ["bank", "cash", "mobile"],
8213
- currencies: ["USD", "TZS", "KES", "CNY"]
8214
- };
8215
- var Enums_default = Enums;
8216
-
8217
8248
  // src/components/accounts/schema.tsx
8218
8249
  import { z as z2 } from "zod";
8219
8250
  var createAccountSchema = z2.object({
@@ -8475,14 +8506,19 @@ var AccountFields = {
8475
8506
  var Feilds_default = AccountFields;
8476
8507
 
8477
8508
  // src/components/accounts/AccountForm.tsx
8478
- import { useParams as useParams4 } from "react-router-dom";
8509
+ import { Navigate as Navigate3, useParams as useParams4 } from "react-router-dom";
8479
8510
  import { jsx as jsx49, jsxs as jsxs36 } from "react/jsx-runtime";
8480
8511
  function AccountForm() {
8512
+ const { enums } = useWarqadConfig();
8481
8513
  const { branchId } = useParams4();
8482
8514
  const { getQuery, getParams, navigate } = useApp_default();
8483
8515
  const id = getQuery("id");
8484
8516
  const type = getParams("type");
8485
8517
  const isEdit = !!id;
8518
+ if (!enums.accountTypes.includes(type)) {
8519
+ message5.error("Invalid account type");
8520
+ return /* @__PURE__ */ jsx49(Navigate3, { to: "/accounts", replace: true });
8521
+ }
8486
8522
  const { post, put, isLoading } = useApis_default();
8487
8523
  const { isLoading: isLoadingGet, get } = useApis_default();
8488
8524
  const methods = useForm2({
@@ -8570,10 +8606,7 @@ function AccountForm() {
8570
8606
  label: "Sex",
8571
8607
  form: methods,
8572
8608
  name: "sex",
8573
- options: Enums_default.sex.map((sex) => ({
8574
- value: sex,
8575
- label: sex
8576
- }))
8609
+ enumName: "sex"
8577
8610
  }
8578
8611
  ),
8579
8612
  /* @__PURE__ */ jsx49(
@@ -8794,7 +8827,7 @@ function LinkUser({ type: initialType = "employee" }) {
8794
8827
  var linkUser_default = LinkUser;
8795
8828
 
8796
8829
  // src/components/users/users.tsx
8797
- import { useMemo as useMemo8 } from "react";
8830
+ import { useMemo as useMemo9 } from "react";
8798
8831
  import { EllipsisVertical as EllipsisVertical2, Info, Mail as Mail2, ShieldCheck, Key } from "lucide-react";
8799
8832
 
8800
8833
  // src/components/users/VerifyEmailForm.tsx
@@ -9234,7 +9267,7 @@ function Users() {
9234
9267
  })
9235
9268
  }
9236
9269
  ].filter(Boolean);
9237
- const columns = useMemo8(
9270
+ const columns = useMemo9(
9238
9271
  () => [
9239
9272
  {
9240
9273
  accessorKey: "email",
@@ -9859,6 +9892,7 @@ import { useEffect as useEffect25 } from "react";
9859
9892
  import { useParams as useParams7 } from "react-router-dom";
9860
9893
  import { jsx as jsx61, jsxs as jsxs47 } from "react/jsx-runtime";
9861
9894
  function WalletForm() {
9895
+ const { enums } = useWarqadConfig();
9862
9896
  const { branchId } = useParams7();
9863
9897
  const { getQuery, navigate } = useApp_default();
9864
9898
  const id = getQuery("id");
@@ -9953,10 +9987,7 @@ function WalletForm() {
9953
9987
  form: methods,
9954
9988
  required: true,
9955
9989
  name: "type",
9956
- options: Enums_default.walletTypes.map((type) => ({
9957
- value: type,
9958
- label: type
9959
- }))
9990
+ enumName: "walletTypes"
9960
9991
  }
9961
9992
  ),
9962
9993
  /* @__PURE__ */ jsx61(
@@ -9966,10 +9997,7 @@ function WalletForm() {
9966
9997
  form: methods,
9967
9998
  name: "currency",
9968
9999
  required: true,
9969
- options: Enums_default.currencies.map((currency) => ({
9970
- value: currency,
9971
- label: currency
9972
- }))
10000
+ enumName: "currencies"
9973
10001
  }
9974
10002
  ),
9975
10003
  /* @__PURE__ */ jsx61(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "warqadui",
3
- "version": "0.0.89",
3
+ "version": "0.0.91",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",