@lasterp/shared 1.0.0-beta.2 → 1.0.0-beta.20
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.
|
@@ -1,29 +1,54 @@
|
|
|
1
1
|
interface Item {
|
|
2
|
+
name: string;
|
|
3
|
+
image: string;
|
|
2
4
|
item_code: string;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
item_name: string;
|
|
6
|
+
item_group: string;
|
|
7
|
+
brand: string;
|
|
8
|
+
os: string;
|
|
9
|
+
release_year: string;
|
|
10
|
+
description: string;
|
|
11
|
+
attributes: string[];
|
|
12
|
+
storages: string[];
|
|
13
|
+
memories: string[];
|
|
14
|
+
colors: Colour[];
|
|
15
|
+
screens: ScreenSpec[];
|
|
16
|
+
images: Image[];
|
|
17
|
+
height: number;
|
|
18
|
+
width: number;
|
|
19
|
+
weight: number;
|
|
13
20
|
}
|
|
14
|
-
interface
|
|
15
|
-
|
|
21
|
+
interface Colour {
|
|
22
|
+
color: string;
|
|
23
|
+
hex: string;
|
|
24
|
+
color_system: string;
|
|
16
25
|
}
|
|
17
26
|
interface Model {
|
|
18
27
|
model_number: string;
|
|
19
28
|
sim_card_type: string;
|
|
20
29
|
connectivity: string;
|
|
21
30
|
}
|
|
22
|
-
interface
|
|
31
|
+
interface ScreenSpec {
|
|
32
|
+
screen: string;
|
|
33
|
+
height: number;
|
|
34
|
+
width: number;
|
|
35
|
+
weight: number;
|
|
36
|
+
}
|
|
37
|
+
interface Image {
|
|
38
|
+
image: string;
|
|
23
39
|
color: string;
|
|
24
|
-
hex: string;
|
|
25
|
-
color_system: string;
|
|
26
40
|
}
|
|
41
|
+
import { z } from "zod";
|
|
42
|
+
declare const ATTRIBUTES: readonly ["Colour", "Storage", "Memory", "Screen"];
|
|
43
|
+
declare const COLOR_SYSTEMS: readonly ["White", "Black", "Yellow", "Red", "Green", "Blue", "Purple", "Orange", "Pink", "Brown", "Gray", "Silver", "Gold"];
|
|
44
|
+
declare const colourFormSchema: unknown;
|
|
45
|
+
declare const screenFormSchema: unknown;
|
|
46
|
+
declare const modelFormSchema: unknown;
|
|
47
|
+
declare const itemFormSchema: unknown;
|
|
48
|
+
type ColourForm = z.infer<typeof colourFormSchema>;
|
|
49
|
+
type ScreenForm = z.infer<typeof screenFormSchema>;
|
|
50
|
+
type ModelForm = z.infer<typeof modelFormSchema>;
|
|
51
|
+
type ItemForm = z.infer<typeof itemFormSchema>;
|
|
27
52
|
interface Globals {
|
|
28
53
|
header: Header;
|
|
29
54
|
footer: Footer;
|
|
@@ -97,6 +122,15 @@ interface Page {
|
|
|
97
122
|
hero?: Hero;
|
|
98
123
|
blocks: Block[];
|
|
99
124
|
}
|
|
125
|
+
interface WorkspaceSidebar {
|
|
126
|
+
label: string;
|
|
127
|
+
header_icon: string;
|
|
128
|
+
items: WorkspaceSidebarItem[];
|
|
129
|
+
}
|
|
130
|
+
interface WorkspaceSidebarItem {
|
|
131
|
+
label: string;
|
|
132
|
+
link_to: string;
|
|
133
|
+
}
|
|
100
134
|
import { FrappeApp, FrappeAuth, FrappeCall } from "frappe-js-sdk";
|
|
101
135
|
import { FrappeDB } from "frappe-js-sdk/lib/db";
|
|
102
136
|
import { FrappeFileUpload } from "frappe-js-sdk/lib/file";
|
|
@@ -131,6 +165,26 @@ interface TokenParams {
|
|
|
131
165
|
/** Type of token to be used for authentication */
|
|
132
166
|
type: "Bearer" | "token";
|
|
133
167
|
}
|
|
168
|
+
interface FrappeResult<T> {
|
|
169
|
+
message: T;
|
|
170
|
+
}
|
|
171
|
+
interface FrappeMeta {
|
|
172
|
+
fields: FrappeMetaField[];
|
|
173
|
+
permissions: {
|
|
174
|
+
can_select: boolean;
|
|
175
|
+
can_read: boolean;
|
|
176
|
+
can_write: boolean;
|
|
177
|
+
can_create: boolean;
|
|
178
|
+
can_delete: boolean;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
interface FrappeMetaField {
|
|
182
|
+
label: string;
|
|
183
|
+
fieldname: string;
|
|
184
|
+
in_list_view: boolean;
|
|
185
|
+
read_only: boolean;
|
|
186
|
+
set_only_once: boolean;
|
|
187
|
+
}
|
|
134
188
|
import { PropsWithChildren } from "react";
|
|
135
189
|
type FrappeProviderProps = PropsWithChildren<{
|
|
136
190
|
/** URL of the Frappe server
|
|
@@ -468,6 +522,7 @@ import { FrappeDoc as FrappeDoc2 } from "frappe-js-sdk/lib/db/types";
|
|
|
468
522
|
* return <div>{data?.name} - {data?.email}</div>
|
|
469
523
|
*/
|
|
470
524
|
declare const useFrappeGetDoc: <T = any>(doctype: string, name?: string, options?: {
|
|
525
|
+
enabled?: boolean;
|
|
471
526
|
staleTime?: number;
|
|
472
527
|
retry?: boolean | number;
|
|
473
528
|
}) => {
|
|
@@ -586,6 +641,16 @@ declare const useFrappeUpdateDoc: <T = any>() => {
|
|
|
586
641
|
isCompleted: boolean;
|
|
587
642
|
reset: () => void;
|
|
588
643
|
};
|
|
644
|
+
declare const useFrappeGetMeta: (doctype: string, options?: {
|
|
645
|
+
staleTime?: number;
|
|
646
|
+
retry?: boolean | number;
|
|
647
|
+
}) => {
|
|
648
|
+
data: FrappeMeta | undefined;
|
|
649
|
+
error: FrappeError | null;
|
|
650
|
+
isLoading: boolean;
|
|
651
|
+
isFetching: boolean;
|
|
652
|
+
refetch: () => void;
|
|
653
|
+
};
|
|
589
654
|
interface VariantSelectorProps<T extends {
|
|
590
655
|
id: string;
|
|
591
656
|
specs: Record<string, string>;
|
|
@@ -611,6 +676,19 @@ declare const useVariantSelector: <T extends {
|
|
|
611
676
|
id: string;
|
|
612
677
|
specs: Record<string, string>;
|
|
613
678
|
}>(props: VariantSelectorProps<T>) => VariantSelectorResult;
|
|
679
|
+
import { JSX, ReactNode } from "react";
|
|
680
|
+
import { StateStorage } from "zustand/middleware";
|
|
681
|
+
type TranslateFn = (message: string, replace?: (string | number)[]) => string;
|
|
682
|
+
interface LocaleProviderProps {
|
|
683
|
+
method: string;
|
|
684
|
+
language: string;
|
|
685
|
+
storage?: StateStorage;
|
|
686
|
+
children: ReactNode;
|
|
687
|
+
}
|
|
688
|
+
declare function LocaleProvider({ method, language, storage, children }: LocaleProviderProps): JSX.Element | null;
|
|
689
|
+
declare function useLocale(): {
|
|
690
|
+
__: TranslateFn;
|
|
691
|
+
};
|
|
614
692
|
interface Category {
|
|
615
693
|
name: string;
|
|
616
694
|
}
|
|
@@ -620,7 +698,7 @@ interface Product {
|
|
|
620
698
|
item_code: string;
|
|
621
699
|
description: string;
|
|
622
700
|
}
|
|
623
|
-
interface ProductVariant
|
|
701
|
+
interface ProductVariant {
|
|
624
702
|
name: string;
|
|
625
703
|
currency: string;
|
|
626
704
|
rate: number;
|
|
@@ -644,12 +722,4 @@ interface ProductContext {
|
|
|
644
722
|
}
|
|
645
723
|
import { camelize, decamelize, camelizeKeys, decamelizeKeys } from "humps";
|
|
646
724
|
declare function equalsIgnoreCase(str1: string, str2: string): boolean;
|
|
647
|
-
|
|
648
|
-
interface ServerProviderProps {
|
|
649
|
-
frappeUrl: string;
|
|
650
|
-
siteName?: string;
|
|
651
|
-
resource: string;
|
|
652
|
-
children: ReactNode;
|
|
653
|
-
}
|
|
654
|
-
declare function ServerProvider({ frappeUrl, siteName, resource, children }: ServerProviderProps): JSX.Element;
|
|
655
|
-
export { useVariantSelector, useSearch, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, equalsIgnoreCase, decamelizeKeys, decamelize, camelizeKeys, camelize, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, ServerProvider, SearchResult, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, ItemVariant, Item, Hero, Header, Globals, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Category, Brand, Block };
|
|
725
|
+
export { useVariantSelector, useSearch, useLocale, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetMeta, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, screenFormSchema, modelFormSchema, itemFormSchema, equalsIgnoreCase, decamelizeKeys, decamelize, colourFormSchema, camelizeKeys, camelize, WorkspaceSidebarItem, WorkspaceSidebar, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, SearchResult, ScreenSpec, ScreenForm, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, ModelForm, Model, LocaleProvider, ItemForm, Item, Image, Hero, Header, Globals, FrappeResult, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeMetaField, FrappeMeta, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, ColourForm, Colour, Category, COLOR_SYSTEMS, Brand, Block, ATTRIBUTES };
|
|
@@ -1,29 +1,54 @@
|
|
|
1
1
|
interface Item {
|
|
2
|
+
name: string;
|
|
3
|
+
image: string;
|
|
2
4
|
item_code: string;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
item_name: string;
|
|
6
|
+
item_group: string;
|
|
7
|
+
brand: string;
|
|
8
|
+
os: string;
|
|
9
|
+
release_year: string;
|
|
10
|
+
description: string;
|
|
11
|
+
attributes: string[];
|
|
12
|
+
storages: string[];
|
|
13
|
+
memories: string[];
|
|
14
|
+
colors: Colour[];
|
|
15
|
+
screens: ScreenSpec[];
|
|
16
|
+
images: Image[];
|
|
17
|
+
height: number;
|
|
18
|
+
width: number;
|
|
19
|
+
weight: number;
|
|
13
20
|
}
|
|
14
|
-
interface
|
|
15
|
-
|
|
21
|
+
interface Colour {
|
|
22
|
+
color: string;
|
|
23
|
+
hex: string;
|
|
24
|
+
color_system: string;
|
|
16
25
|
}
|
|
17
26
|
interface Model {
|
|
18
27
|
model_number: string;
|
|
19
28
|
sim_card_type: string;
|
|
20
29
|
connectivity: string;
|
|
21
30
|
}
|
|
22
|
-
interface
|
|
31
|
+
interface ScreenSpec {
|
|
32
|
+
screen: string;
|
|
33
|
+
height: number;
|
|
34
|
+
width: number;
|
|
35
|
+
weight: number;
|
|
36
|
+
}
|
|
37
|
+
interface Image {
|
|
38
|
+
image: string;
|
|
23
39
|
color: string;
|
|
24
|
-
hex: string;
|
|
25
|
-
color_system: string;
|
|
26
40
|
}
|
|
41
|
+
import { z } from "zod";
|
|
42
|
+
declare const ATTRIBUTES: readonly ["Colour", "Storage", "Memory", "Screen"];
|
|
43
|
+
declare const COLOR_SYSTEMS: readonly ["White", "Black", "Yellow", "Red", "Green", "Blue", "Purple", "Orange", "Pink", "Brown", "Gray", "Silver", "Gold"];
|
|
44
|
+
declare const colourFormSchema: unknown;
|
|
45
|
+
declare const screenFormSchema: unknown;
|
|
46
|
+
declare const modelFormSchema: unknown;
|
|
47
|
+
declare const itemFormSchema: unknown;
|
|
48
|
+
type ColourForm = z.infer<typeof colourFormSchema>;
|
|
49
|
+
type ScreenForm = z.infer<typeof screenFormSchema>;
|
|
50
|
+
type ModelForm = z.infer<typeof modelFormSchema>;
|
|
51
|
+
type ItemForm = z.infer<typeof itemFormSchema>;
|
|
27
52
|
interface Globals {
|
|
28
53
|
header: Header;
|
|
29
54
|
footer: Footer;
|
|
@@ -97,6 +122,15 @@ interface Page {
|
|
|
97
122
|
hero?: Hero;
|
|
98
123
|
blocks: Block[];
|
|
99
124
|
}
|
|
125
|
+
interface WorkspaceSidebar {
|
|
126
|
+
label: string;
|
|
127
|
+
header_icon: string;
|
|
128
|
+
items: WorkspaceSidebarItem[];
|
|
129
|
+
}
|
|
130
|
+
interface WorkspaceSidebarItem {
|
|
131
|
+
label: string;
|
|
132
|
+
link_to: string;
|
|
133
|
+
}
|
|
100
134
|
import { FrappeApp, FrappeAuth, FrappeCall } from "frappe-js-sdk";
|
|
101
135
|
import { FrappeDB } from "frappe-js-sdk/lib/db";
|
|
102
136
|
import { FrappeFileUpload } from "frappe-js-sdk/lib/file";
|
|
@@ -131,6 +165,26 @@ interface TokenParams {
|
|
|
131
165
|
/** Type of token to be used for authentication */
|
|
132
166
|
type: "Bearer" | "token";
|
|
133
167
|
}
|
|
168
|
+
interface FrappeResult<T> {
|
|
169
|
+
message: T;
|
|
170
|
+
}
|
|
171
|
+
interface FrappeMeta {
|
|
172
|
+
fields: FrappeMetaField[];
|
|
173
|
+
permissions: {
|
|
174
|
+
can_select: boolean;
|
|
175
|
+
can_read: boolean;
|
|
176
|
+
can_write: boolean;
|
|
177
|
+
can_create: boolean;
|
|
178
|
+
can_delete: boolean;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
interface FrappeMetaField {
|
|
182
|
+
label: string;
|
|
183
|
+
fieldname: string;
|
|
184
|
+
in_list_view: boolean;
|
|
185
|
+
read_only: boolean;
|
|
186
|
+
set_only_once: boolean;
|
|
187
|
+
}
|
|
134
188
|
import { PropsWithChildren } from "react";
|
|
135
189
|
type FrappeProviderProps = PropsWithChildren<{
|
|
136
190
|
/** URL of the Frappe server
|
|
@@ -468,6 +522,7 @@ import { FrappeDoc as FrappeDoc2 } from "frappe-js-sdk/lib/db/types";
|
|
|
468
522
|
* return <div>{data?.name} - {data?.email}</div>
|
|
469
523
|
*/
|
|
470
524
|
declare const useFrappeGetDoc: <T = any>(doctype: string, name?: string, options?: {
|
|
525
|
+
enabled?: boolean;
|
|
471
526
|
staleTime?: number;
|
|
472
527
|
retry?: boolean | number;
|
|
473
528
|
}) => {
|
|
@@ -586,6 +641,16 @@ declare const useFrappeUpdateDoc: <T = any>() => {
|
|
|
586
641
|
isCompleted: boolean;
|
|
587
642
|
reset: () => void;
|
|
588
643
|
};
|
|
644
|
+
declare const useFrappeGetMeta: (doctype: string, options?: {
|
|
645
|
+
staleTime?: number;
|
|
646
|
+
retry?: boolean | number;
|
|
647
|
+
}) => {
|
|
648
|
+
data: FrappeMeta | undefined;
|
|
649
|
+
error: FrappeError | null;
|
|
650
|
+
isLoading: boolean;
|
|
651
|
+
isFetching: boolean;
|
|
652
|
+
refetch: () => void;
|
|
653
|
+
};
|
|
589
654
|
interface VariantSelectorProps<T extends {
|
|
590
655
|
id: string;
|
|
591
656
|
specs: Record<string, string>;
|
|
@@ -611,6 +676,19 @@ declare const useVariantSelector: <T extends {
|
|
|
611
676
|
id: string;
|
|
612
677
|
specs: Record<string, string>;
|
|
613
678
|
}>(props: VariantSelectorProps<T>) => VariantSelectorResult;
|
|
679
|
+
import { JSX, ReactNode } from "react";
|
|
680
|
+
import { StateStorage } from "zustand/middleware";
|
|
681
|
+
type TranslateFn = (message: string, replace?: (string | number)[]) => string;
|
|
682
|
+
interface LocaleProviderProps {
|
|
683
|
+
method: string;
|
|
684
|
+
language: string;
|
|
685
|
+
storage?: StateStorage;
|
|
686
|
+
children: ReactNode;
|
|
687
|
+
}
|
|
688
|
+
declare function LocaleProvider({ method, language, storage, children }: LocaleProviderProps): JSX.Element | null;
|
|
689
|
+
declare function useLocale(): {
|
|
690
|
+
__: TranslateFn;
|
|
691
|
+
};
|
|
614
692
|
interface Category {
|
|
615
693
|
name: string;
|
|
616
694
|
}
|
|
@@ -620,7 +698,7 @@ interface Product {
|
|
|
620
698
|
item_code: string;
|
|
621
699
|
description: string;
|
|
622
700
|
}
|
|
623
|
-
interface ProductVariant
|
|
701
|
+
interface ProductVariant {
|
|
624
702
|
name: string;
|
|
625
703
|
currency: string;
|
|
626
704
|
rate: number;
|
|
@@ -644,12 +722,4 @@ interface ProductContext {
|
|
|
644
722
|
}
|
|
645
723
|
import { camelize, decamelize, camelizeKeys, decamelizeKeys } from "humps";
|
|
646
724
|
declare function equalsIgnoreCase(str1: string, str2: string): boolean;
|
|
647
|
-
|
|
648
|
-
interface ServerProviderProps {
|
|
649
|
-
frappeUrl: string;
|
|
650
|
-
siteName?: string;
|
|
651
|
-
resource: string;
|
|
652
|
-
children: ReactNode;
|
|
653
|
-
}
|
|
654
|
-
declare function ServerProvider({ frappeUrl, siteName, resource, children }: ServerProviderProps): JSX.Element;
|
|
655
|
-
export { useVariantSelector, useSearch, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, equalsIgnoreCase, decamelizeKeys, decamelize, camelizeKeys, camelize, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, ServerProvider, SearchResult, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, Model, ItemVariant, Item, Hero, Header, Globals, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, Colour, Category, Brand, Block };
|
|
725
|
+
export { useVariantSelector, useSearch, useLocale, useFrappeUpdateDoc, useFrappePutCall, useFrappePrefetchDoc, useFrappePostCall, useFrappeGetMeta, useFrappeGetDocList, useFrappeGetDocCount, useFrappeGetDoc, useFrappeGetCall, useFrappeFileUpload, useFrappeEventListener, useFrappeDocumentEventListener, useFrappeDocTypeEventListener, useFrappeDeleteDoc, useFrappeDeleteCall, useFrappeCreateDoc, useFrappeAuth, screenFormSchema, modelFormSchema, itemFormSchema, equalsIgnoreCase, decamelizeKeys, decamelize, colourFormSchema, camelizeKeys, camelize, WorkspaceSidebarItem, WorkspaceSidebar, ViewerEventData, VariantSelectorResult, VariantSelectorProps, VariantSelectorOption, UseFrappeFileUploadReturnType, TopbarItem, Topbar, TokenParams, ShopContext, SearchResult, ScreenSpec, ScreenForm, ProductVariant, ProductContext, Product, Page, NavbarSubItemGroup, NavbarSubItem, NavbarItem, ModelForm, Model, LocaleProvider, ItemForm, Item, Image, Hero, Header, Globals, FrappeResult, FrappeProviderProps, FrappeProvider, FrappeMutationResult, FrappeMetaField, FrappeMeta, FrappeFileUploadResponse, FrappeError, FrappeContext, FrappeConfig, FooterItemGroup, FooterItem, Footer, DocumentUpdateEventData, DocTypeListUpdateEventData, ColourForm, Colour, Category, COLOR_SYSTEMS, Brand, Block, ATTRIBUTES };
|
|
@@ -1,4 +1,52 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
// src/catalog/schema.ts
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
var ATTRIBUTES = ["Colour", "Storage", "Memory", "Screen"];
|
|
5
|
+
var COLOR_SYSTEMS = [
|
|
6
|
+
"White",
|
|
7
|
+
"Black",
|
|
8
|
+
"Yellow",
|
|
9
|
+
"Red",
|
|
10
|
+
"Green",
|
|
11
|
+
"Blue",
|
|
12
|
+
"Purple",
|
|
13
|
+
"Orange",
|
|
14
|
+
"Pink",
|
|
15
|
+
"Brown",
|
|
16
|
+
"Gray",
|
|
17
|
+
"Silver",
|
|
18
|
+
"Gold"
|
|
19
|
+
];
|
|
20
|
+
var colourFormSchema = z.object({
|
|
21
|
+
color: z.string().min(1, "Color is required"),
|
|
22
|
+
color_hex: z.string().optional(),
|
|
23
|
+
color_system: z.enum(COLOR_SYSTEMS).optional(),
|
|
24
|
+
images: z.array(z.union([z.instanceof(File), z.string()])).default([])
|
|
25
|
+
});
|
|
26
|
+
var screenFormSchema = z.object({
|
|
27
|
+
screen: z.string().min(1, "Screen is required"),
|
|
28
|
+
height: z.number().positive().optional(),
|
|
29
|
+
width: z.number().positive().optional(),
|
|
30
|
+
weight: z.number().positive().optional()
|
|
31
|
+
});
|
|
32
|
+
var modelFormSchema = z.object({
|
|
33
|
+
model: z.string().min(1, "Model is required"),
|
|
34
|
+
sim_card_type: z.string().optional(),
|
|
35
|
+
connectivity: z.array(z.string())
|
|
36
|
+
});
|
|
37
|
+
var itemFormSchema = z.object({
|
|
38
|
+
item_code: z.string().min(1, "Item is required"),
|
|
39
|
+
item_group: z.string().optional(),
|
|
40
|
+
brand: z.string().optional(),
|
|
41
|
+
os: z.string().optional(),
|
|
42
|
+
release_year: z.number().int().min(1900).max(2100).optional(),
|
|
43
|
+
attributes: z.array(z.enum(ATTRIBUTES)),
|
|
44
|
+
colours: z.array(colourFormSchema),
|
|
45
|
+
storages: z.array(z.string()),
|
|
46
|
+
memories: z.array(z.string()),
|
|
47
|
+
screens: z.array(screenFormSchema),
|
|
48
|
+
models: z.array(modelFormSchema)
|
|
49
|
+
});
|
|
2
50
|
// src/frappe/provider.tsx
|
|
3
51
|
import { useMemo, createContext } from "react";
|
|
4
52
|
import { FrappeApp } from "frappe-js-sdk";
|
|
@@ -58,7 +106,7 @@ var FrappeProvider = ({
|
|
|
58
106
|
children,
|
|
59
107
|
customHeaders
|
|
60
108
|
}) => {
|
|
61
|
-
const
|
|
109
|
+
const config = useMemo(() => {
|
|
62
110
|
const frappe = new FrappeApp(url, tokenParams, undefined, customHeaders);
|
|
63
111
|
return {
|
|
64
112
|
url,
|
|
@@ -72,7 +120,7 @@ var FrappeProvider = ({
|
|
|
72
120
|
};
|
|
73
121
|
}, [url, tokenParams, enableSocket, socketPort, siteName, customHeaders]);
|
|
74
122
|
return /* @__PURE__ */ jsx(FrappeContext.Provider, {
|
|
75
|
-
value:
|
|
123
|
+
value: config,
|
|
76
124
|
children
|
|
77
125
|
});
|
|
78
126
|
};
|
|
@@ -161,7 +209,15 @@ var useFrappeGetCall = (method, params, options, type = "GET") => {
|
|
|
161
209
|
const queryKey = ["frappeCall", type, method, url];
|
|
162
210
|
const { data, error, isLoading, isFetching, refetch } = useQuery2({
|
|
163
211
|
queryKey,
|
|
164
|
-
queryFn:
|
|
212
|
+
queryFn: async () => {
|
|
213
|
+
if (type === "GET") {
|
|
214
|
+
const response = await call.get(method, params);
|
|
215
|
+
return response.message;
|
|
216
|
+
} else {
|
|
217
|
+
const response = await call.post(method, params);
|
|
218
|
+
return response.message;
|
|
219
|
+
}
|
|
220
|
+
},
|
|
165
221
|
enabled: (options?.enabled ?? true) && !!method,
|
|
166
222
|
staleTime: options?.staleTime,
|
|
167
223
|
retry: options?.retry ?? false
|
|
@@ -374,7 +430,7 @@ var useFrappeGetDoc = (doctype, name, options) => {
|
|
|
374
430
|
const { data, error, isLoading, isFetching, refetch } = useQuery4({
|
|
375
431
|
queryKey,
|
|
376
432
|
queryFn: () => db.getDoc(doctype, name),
|
|
377
|
-
enabled:
|
|
433
|
+
enabled: options?.enabled ?? true,
|
|
378
434
|
staleTime: options?.staleTime ?? 5 * 60 * 1000,
|
|
379
435
|
retry: options?.retry ?? false
|
|
380
436
|
});
|
|
@@ -465,6 +521,29 @@ var useFrappeUpdateDoc = () => {
|
|
|
465
521
|
reset
|
|
466
522
|
};
|
|
467
523
|
};
|
|
524
|
+
// src/frappe/hooks/meta.ts
|
|
525
|
+
import { useContext as useContext12 } from "react";
|
|
526
|
+
import { useQuery as useQuery6 } from "@tanstack/react-query";
|
|
527
|
+
var useFrappeGetMeta = (doctype, options) => {
|
|
528
|
+
const { url, call } = useContext12(FrappeContext);
|
|
529
|
+
const { data, error, isLoading, isFetching, refetch } = useQuery6({
|
|
530
|
+
queryKey: ["meta", url, doctype],
|
|
531
|
+
queryFn: async () => {
|
|
532
|
+
const response = await call.get("lasterp.api.get_meta", { doctype });
|
|
533
|
+
return response.message;
|
|
534
|
+
},
|
|
535
|
+
enabled: !!doctype,
|
|
536
|
+
staleTime: options?.staleTime ?? Infinity,
|
|
537
|
+
retry: options?.retry ?? false
|
|
538
|
+
});
|
|
539
|
+
return {
|
|
540
|
+
data,
|
|
541
|
+
error,
|
|
542
|
+
isLoading,
|
|
543
|
+
isFetching,
|
|
544
|
+
refetch
|
|
545
|
+
};
|
|
546
|
+
};
|
|
468
547
|
// src/hooks/use-variant-selector/hook.ts
|
|
469
548
|
import { useCallback as useCallback4, useMemo as useMemo2, useState as useState5 } from "react";
|
|
470
549
|
|
|
@@ -570,66 +649,72 @@ var useVariantSelector = (props) => {
|
|
|
570
649
|
getOptions: (key) => options[key] || []
|
|
571
650
|
};
|
|
572
651
|
};
|
|
573
|
-
// src/
|
|
574
|
-
import { camelize, decamelize, camelizeKeys, decamelizeKeys } from "humps";
|
|
575
|
-
function equalsIgnoreCase(str1, str2) {
|
|
576
|
-
return str1.localeCompare(str2, undefined, { sensitivity: "accent" }) === 0;
|
|
577
|
-
}
|
|
578
|
-
// src/context/server-provider.node.tsx
|
|
652
|
+
// src/locale/provider.tsx
|
|
579
653
|
import {
|
|
654
|
+
createContext as createContext2,
|
|
580
655
|
useCallback as useCallback5,
|
|
656
|
+
useContext as useContext13,
|
|
581
657
|
useEffect as useEffect4,
|
|
582
|
-
|
|
658
|
+
useState as useState6
|
|
583
659
|
} from "react";
|
|
584
|
-
import { useLogto } from "@logto/react";
|
|
585
660
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
661
|
+
function translate(message, replace, messages = {}) {
|
|
662
|
+
let translated = messages[message] ?? message;
|
|
663
|
+
replace?.forEach((val, i) => {
|
|
664
|
+
translated = translated.replace(`{${i}}`, String(val));
|
|
665
|
+
});
|
|
666
|
+
return translated;
|
|
667
|
+
}
|
|
668
|
+
var LocaleContext = createContext2((message) => message);
|
|
669
|
+
function LocaleProvider({
|
|
670
|
+
method,
|
|
671
|
+
language,
|
|
672
|
+
storage,
|
|
591
673
|
children
|
|
592
674
|
}) {
|
|
593
|
-
const
|
|
594
|
-
const tokenRef = useRef("");
|
|
595
|
-
const fetchedAtRef = useRef(0);
|
|
596
|
-
const isRefreshingRef = useRef(false);
|
|
597
|
-
const refresh = useCallback5(async () => {
|
|
598
|
-
const token = await getAccessToken(resource);
|
|
599
|
-
if (token) {
|
|
600
|
-
tokenRef.current = token;
|
|
601
|
-
fetchedAtRef.current = Date.now();
|
|
602
|
-
}
|
|
603
|
-
}, [getAccessToken, resource]);
|
|
675
|
+
const [messages, setMessages] = useState6({});
|
|
604
676
|
useEffect4(() => {
|
|
605
|
-
if (
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
677
|
+
if (!storage)
|
|
678
|
+
return;
|
|
679
|
+
const key = `locale:${language}`;
|
|
680
|
+
Promise.resolve(storage.getItem(key)).then((cached) => {
|
|
681
|
+
if (cached)
|
|
682
|
+
setMessages(JSON.parse(cached));
|
|
683
|
+
}).catch(() => {});
|
|
684
|
+
}, [language, storage]);
|
|
685
|
+
const { data, isLoading } = useFrappeGetCall(method, { lang: language }, { staleTime: Infinity });
|
|
686
|
+
useEffect4(() => {
|
|
687
|
+
if (!data)
|
|
688
|
+
return;
|
|
689
|
+
setMessages(data);
|
|
690
|
+
storage?.setItem(`locale:${language}`, JSON.stringify(data));
|
|
691
|
+
}, [data, language, storage]);
|
|
692
|
+
const __ = useCallback5((message, replace) => translate(message, replace, messages), [messages]);
|
|
693
|
+
if (isLoading && Object.keys(messages).length === 0)
|
|
694
|
+
return null;
|
|
695
|
+
return /* @__PURE__ */ jsx2(LocaleContext.Provider, {
|
|
696
|
+
value: __,
|
|
623
697
|
children
|
|
624
698
|
});
|
|
625
699
|
}
|
|
700
|
+
function useLocale() {
|
|
701
|
+
const __ = useContext13(LocaleContext);
|
|
702
|
+
return { __ };
|
|
703
|
+
}
|
|
704
|
+
// src/utils/char.ts
|
|
705
|
+
import { camelize, decamelize, camelizeKeys, decamelizeKeys } from "humps";
|
|
706
|
+
function equalsIgnoreCase(str1, str2) {
|
|
707
|
+
return str1.localeCompare(str2, undefined, { sensitivity: "accent" }) === 0;
|
|
708
|
+
}
|
|
626
709
|
export {
|
|
627
710
|
useVariantSelector,
|
|
628
711
|
useSearch,
|
|
712
|
+
useLocale,
|
|
629
713
|
useFrappeUpdateDoc,
|
|
630
714
|
useFrappePutCall,
|
|
631
715
|
useFrappePrefetchDoc,
|
|
632
716
|
useFrappePostCall,
|
|
717
|
+
useFrappeGetMeta,
|
|
633
718
|
useFrappeGetDocList,
|
|
634
719
|
useFrappeGetDocCount,
|
|
635
720
|
useFrappeGetDoc,
|
|
@@ -642,12 +727,18 @@ export {
|
|
|
642
727
|
useFrappeDeleteCall,
|
|
643
728
|
useFrappeCreateDoc,
|
|
644
729
|
useFrappeAuth,
|
|
730
|
+
screenFormSchema,
|
|
731
|
+
modelFormSchema,
|
|
732
|
+
itemFormSchema,
|
|
645
733
|
equalsIgnoreCase,
|
|
646
734
|
decamelizeKeys,
|
|
647
735
|
decamelize,
|
|
736
|
+
colourFormSchema,
|
|
648
737
|
camelizeKeys,
|
|
649
738
|
camelize,
|
|
650
|
-
|
|
739
|
+
LocaleProvider,
|
|
651
740
|
FrappeProvider,
|
|
652
|
-
FrappeContext
|
|
741
|
+
FrappeContext,
|
|
742
|
+
COLOR_SYSTEMS,
|
|
743
|
+
ATTRIBUTES
|
|
653
744
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lasterp/shared",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.20",
|
|
4
4
|
"description": "Shared repo for webapp and native app",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -20,38 +20,33 @@
|
|
|
20
20
|
"typescript": "^5.9.3"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
+
"@tanstack/react-query": "^5.90.21",
|
|
23
24
|
"react": ">=18.0.0",
|
|
24
25
|
"react-dom": ">=18.0.0",
|
|
25
|
-
"typescript": ">=4.5.0"
|
|
26
|
-
"@tanstack/react-query": "^5.90.21",
|
|
27
|
-
"@logto/react": "^4.0.13",
|
|
28
|
-
"@logto/rn": "^1.1.0"
|
|
26
|
+
"typescript": ">=4.5.0"
|
|
29
27
|
},
|
|
30
28
|
"peerDependenciesMeta": {
|
|
31
29
|
"typescript": {
|
|
32
30
|
"optional": true
|
|
33
|
-
},
|
|
34
|
-
"@logto/react": {
|
|
35
|
-
"optional": true
|
|
36
|
-
},
|
|
37
|
-
"@logto/rn": {
|
|
38
|
-
"optional": true
|
|
39
31
|
}
|
|
40
32
|
},
|
|
41
33
|
"type": "module",
|
|
42
34
|
"exports": {
|
|
43
35
|
".": {
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js",
|
|
38
|
+
"require": "./dist/index.cjs"
|
|
47
39
|
},
|
|
48
40
|
"./package.json": "./package.json"
|
|
49
41
|
},
|
|
50
42
|
"module": "./dist/index.js",
|
|
43
|
+
"main": "./dist/index.cjs",
|
|
51
44
|
"types": "./dist/index.d.ts",
|
|
52
45
|
"dependencies": {
|
|
53
46
|
"frappe-js-sdk": "^1.12.0",
|
|
54
47
|
"humps": "^2.0.1",
|
|
55
|
-
"socket.io-client": "^4.8.3"
|
|
48
|
+
"socket.io-client": "^4.8.3",
|
|
49
|
+
"zod": "^4.3.6",
|
|
50
|
+
"zustand": "^5.0.11"
|
|
56
51
|
}
|
|
57
52
|
}
|