@kiosinc/commons-rn 0.1.7 → 0.1.8
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/lib/commonjs/auth/index.js +3 -10
- package/lib/commonjs/auth/index.js.map +1 -1
- package/lib/commonjs/auth/screens/validators.js +4 -4
- package/lib/commonjs/auth/screens/validators.js.map +1 -1
- package/lib/commonjs/constants/index.js +11 -0
- package/lib/commonjs/constants/index.js.map +1 -0
- package/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/selectBusiness/CreateBusinessBottomSheet.js +68 -0
- package/lib/commonjs/selectBusiness/CreateBusinessBottomSheet.js.map +1 -0
- package/lib/commonjs/selectBusiness/SelectBusiness.js +89 -0
- package/lib/commonjs/selectBusiness/SelectBusiness.js.map +1 -0
- package/lib/commonjs/selectBusiness/index.js +20 -0
- package/lib/commonjs/selectBusiness/index.js.map +1 -0
- package/lib/commonjs/selectBusiness/queryKeys.js +11 -0
- package/lib/commonjs/selectBusiness/queryKeys.js.map +1 -0
- package/lib/commonjs/selectBusiness/useBusinesses.js +34 -0
- package/lib/commonjs/selectBusiness/useBusinesses.js.map +1 -0
- package/lib/commonjs/selectBusiness/useCreateBusiness.js +24 -0
- package/lib/commonjs/selectBusiness/useCreateBusiness.js.map +1 -0
- package/lib/commonjs/selectBusiness/useMultiSnapBottomSheetRef.js +35 -0
- package/lib/commonjs/selectBusiness/useMultiSnapBottomSheetRef.js.map +1 -0
- package/lib/commonjs/selectBusiness/useSingleSnapBottomSheetRef.js +27 -0
- package/lib/commonjs/selectBusiness/useSingleSnapBottomSheetRef.js.map +1 -0
- package/lib/commonjs/types/@gorhom/bottom-sheet.js +2 -0
- package/lib/commonjs/types/@gorhom/bottom-sheet.js.map +1 -0
- package/lib/commonjs/utils/index.js +14 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/module/auth/index.js +0 -1
- package/lib/module/auth/index.js.map +1 -1
- package/lib/module/auth/screens/validators.js +1 -1
- package/lib/module/auth/screens/validators.js.map +1 -1
- package/lib/module/constants/index.js +5 -0
- package/lib/module/constants/index.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/selectBusiness/CreateBusinessBottomSheet.js +60 -0
- package/lib/module/selectBusiness/CreateBusinessBottomSheet.js.map +1 -0
- package/lib/module/selectBusiness/SelectBusiness.js +81 -0
- package/lib/module/selectBusiness/SelectBusiness.js.map +1 -0
- package/lib/module/selectBusiness/index.js +3 -0
- package/lib/module/selectBusiness/index.js.map +1 -0
- package/lib/module/selectBusiness/queryKeys.js +5 -0
- package/lib/module/selectBusiness/queryKeys.js.map +1 -0
- package/lib/module/selectBusiness/useBusinesses.js +25 -0
- package/lib/module/selectBusiness/useBusinesses.js.map +1 -0
- package/lib/module/selectBusiness/useCreateBusiness.js +17 -0
- package/lib/module/selectBusiness/useCreateBusiness.js.map +1 -0
- package/lib/module/selectBusiness/useMultiSnapBottomSheetRef.js +28 -0
- package/lib/module/selectBusiness/useMultiSnapBottomSheetRef.js.map +1 -0
- package/lib/module/selectBusiness/useSingleSnapBottomSheetRef.js +20 -0
- package/lib/module/selectBusiness/useSingleSnapBottomSheetRef.js.map +1 -0
- package/lib/module/types/@gorhom/bottom-sheet.js +2 -0
- package/lib/module/types/@gorhom/bottom-sheet.js.map +1 -0
- package/lib/module/utils/index.js +7 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/src/auth/index.d.ts +0 -1
- package/lib/typescript/src/auth/index.d.ts.map +1 -1
- package/lib/typescript/src/auth/screens/validators.d.ts +0 -1
- package/lib/typescript/src/auth/screens/validators.d.ts.map +1 -1
- package/lib/typescript/src/components/BottomSheet.d.ts +1 -1
- package/lib/typescript/src/components/BottomSheet.d.ts.map +1 -1
- package/lib/typescript/src/constants/index.d.ts +5 -0
- package/lib/typescript/src/constants/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/selectBusiness/CreateBusinessBottomSheet.d.ts +7 -0
- package/lib/typescript/src/selectBusiness/CreateBusinessBottomSheet.d.ts.map +1 -0
- package/lib/typescript/src/selectBusiness/SelectBusiness.d.ts +3 -0
- package/lib/typescript/src/selectBusiness/SelectBusiness.d.ts.map +1 -0
- package/lib/typescript/src/selectBusiness/index.d.ts +3 -0
- package/lib/typescript/src/selectBusiness/index.d.ts.map +1 -0
- package/lib/typescript/src/selectBusiness/queryKeys.d.ts +5 -0
- package/lib/typescript/src/selectBusiness/queryKeys.d.ts.map +1 -0
- package/lib/typescript/src/selectBusiness/useBusinesses.d.ts +6 -0
- package/lib/typescript/src/selectBusiness/useBusinesses.d.ts.map +1 -0
- package/lib/typescript/src/selectBusiness/useCreateBusiness.d.ts +4 -0
- package/lib/typescript/src/selectBusiness/useCreateBusiness.d.ts.map +1 -0
- package/lib/typescript/src/selectBusiness/useMultiSnapBottomSheetRef.d.ts +28 -0
- package/lib/typescript/src/selectBusiness/useMultiSnapBottomSheetRef.d.ts.map +1 -0
- package/lib/typescript/src/selectBusiness/useSingleSnapBottomSheetRef.d.ts +14 -0
- package/lib/typescript/src/selectBusiness/useSingleSnapBottomSheetRef.d.ts.map +1 -0
- package/lib/typescript/src/types/@gorhom/bottom-sheet.d.ts +2 -0
- package/lib/typescript/src/types/@gorhom/bottom-sheet.d.ts.map +1 -0
- package/lib/typescript/src/utils/index.d.ts +2 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -0
- package/package.json +6 -2
- package/src/auth/index.ts +0 -1
- package/src/auth/screens/validators.ts +1 -3
- package/src/constants/index.ts +6 -0
- package/src/index.tsx +1 -0
- package/src/selectBusiness/CreateBusinessBottomSheet.tsx +69 -0
- package/src/selectBusiness/SelectBusiness.tsx +82 -0
- package/src/selectBusiness/index.ts +2 -0
- package/src/selectBusiness/queryKeys.ts +5 -0
- package/src/selectBusiness/useBusinesses.ts +33 -0
- package/src/selectBusiness/useCreateBusiness.ts +18 -0
- package/src/selectBusiness/useMultiSnapBottomSheetRef.ts +46 -0
- package/src/selectBusiness/useSingleSnapBottomSheetRef.ts +23 -0
- package/src/types/@gorhom/bottom-sheet.ts +1 -0
- package/src/utils/index.ts +11 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { forwardRef, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Text,
|
|
4
|
+
Button,
|
|
5
|
+
KeyboardAvoidingView,
|
|
6
|
+
TextInput,
|
|
7
|
+
View,
|
|
8
|
+
BottomSheet,
|
|
9
|
+
} from '../components';
|
|
10
|
+
import { BottomSheetTextInput } from '@gorhom/bottom-sheet';
|
|
11
|
+
import { getPercentageFromHeight } from '../utils';
|
|
12
|
+
import { useTranslation } from 'react-i18next';
|
|
13
|
+
import { useCreateBusiness } from './useCreateBusiness';
|
|
14
|
+
|
|
15
|
+
type CreateBusinessBottomSheetProps = {
|
|
16
|
+
close: () => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const CreateBusinessBottomSheet = forwardRef(
|
|
20
|
+
({ close }: CreateBusinessBottomSheetProps, ref) => {
|
|
21
|
+
const [name, setName] = useState('');
|
|
22
|
+
const { mutate: createNewMenuGroup, isLoading } = useCreateBusiness({
|
|
23
|
+
onSuccess: () => {
|
|
24
|
+
close();
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const { t } = useTranslation();
|
|
28
|
+
|
|
29
|
+
const onRename = () => {
|
|
30
|
+
createNewMenuGroup({
|
|
31
|
+
name,
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<BottomSheet
|
|
37
|
+
pressBehavior="close"
|
|
38
|
+
snapPoints={[getPercentageFromHeight(220)]}
|
|
39
|
+
ref={ref as any}
|
|
40
|
+
>
|
|
41
|
+
<View px="16" bg="background" flex={1}>
|
|
42
|
+
<Text pt="16" variant="titleLarge">
|
|
43
|
+
{t('home.createBusiness')}
|
|
44
|
+
</Text>
|
|
45
|
+
<KeyboardAvoidingView>
|
|
46
|
+
<TextInput
|
|
47
|
+
render={(props) => {
|
|
48
|
+
return <BottomSheetTextInput {...props} />;
|
|
49
|
+
}}
|
|
50
|
+
mt="16"
|
|
51
|
+
mode="outlined"
|
|
52
|
+
onChangeText={setName}
|
|
53
|
+
value={name}
|
|
54
|
+
label={t('home.businessName')}
|
|
55
|
+
/>
|
|
56
|
+
<View mt="16" flexDirection="row" justifyContent="flex-end">
|
|
57
|
+
<Button mode="text" onPress={close}>
|
|
58
|
+
{t('cancel')}
|
|
59
|
+
</Button>
|
|
60
|
+
<Button loading={isLoading} mode="text" onPress={onRename}>
|
|
61
|
+
{t('create')}
|
|
62
|
+
</Button>
|
|
63
|
+
</View>
|
|
64
|
+
</KeyboardAvoidingView>
|
|
65
|
+
</View>
|
|
66
|
+
</BottomSheet>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Card, FAB, Header, ParentView, Text, View } from '../components';
|
|
3
|
+
import { FlashList } from '@shopify/flash-list';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { ActivityIndicator } from 'react-native-paper';
|
|
6
|
+
import { useMMKVString } from 'react-native-mmkv';
|
|
7
|
+
import { type NavigationProp, useNavigation } from '@react-navigation/native';
|
|
8
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
9
|
+
import { CreateBusinessBottomSheet } from './CreateBusinessBottomSheet';
|
|
10
|
+
import { useBusinesses } from './useBusinesses';
|
|
11
|
+
import { MMKV_KEYS } from '../constants';
|
|
12
|
+
import { useSingleSnapBottomSheetRef } from './useSingleSnapBottomSheetRef';
|
|
13
|
+
|
|
14
|
+
const BusinessCard = ({
|
|
15
|
+
business,
|
|
16
|
+
onSelect,
|
|
17
|
+
}: {
|
|
18
|
+
business: { id: string; name: string };
|
|
19
|
+
onSelect: () => void;
|
|
20
|
+
}) => {
|
|
21
|
+
return (
|
|
22
|
+
<Card bg="onSecondary" p="16" mx="2" mb="12" mt="2" onPress={onSelect}>
|
|
23
|
+
<Text variant="bodyMedium">{business.name}</Text>
|
|
24
|
+
</Card>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const SelectBusiness = () => {
|
|
29
|
+
const { t } = useTranslation();
|
|
30
|
+
const [_, setBusinessId] = useMMKVString(MMKV_KEYS.BUSINESS_ID);
|
|
31
|
+
|
|
32
|
+
const { data: businesses, isFetching } = useBusinesses();
|
|
33
|
+
|
|
34
|
+
const navigation = useNavigation<NavigationProp<RootStackType>>();
|
|
35
|
+
const queryClient = useQueryClient();
|
|
36
|
+
const createBusinessBottomSheet = useSingleSnapBottomSheetRef();
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ParentView flex={1} backgroundColor="background">
|
|
40
|
+
<Header title={t('home.selectBusiness')} />
|
|
41
|
+
<View px="16" flex={1}>
|
|
42
|
+
{isFetching && (
|
|
43
|
+
<View flex={1} alignItems="center" justifyContent="center">
|
|
44
|
+
<ActivityIndicator />
|
|
45
|
+
</View>
|
|
46
|
+
)}
|
|
47
|
+
{!isFetching && (
|
|
48
|
+
<FlashList
|
|
49
|
+
showsVerticalScrollIndicator={false}
|
|
50
|
+
data={businesses}
|
|
51
|
+
renderItem={({ item }) => (
|
|
52
|
+
<BusinessCard
|
|
53
|
+
onSelect={() => {
|
|
54
|
+
if (navigation.canGoBack()) {
|
|
55
|
+
navigation.goBack();
|
|
56
|
+
}
|
|
57
|
+
queryClient.clear();
|
|
58
|
+
setBusinessId(item.id);
|
|
59
|
+
}}
|
|
60
|
+
business={item}
|
|
61
|
+
/>
|
|
62
|
+
)}
|
|
63
|
+
estimatedItemSize={200}
|
|
64
|
+
/>
|
|
65
|
+
)}
|
|
66
|
+
<View position="absolute" bottom={16} right={16}>
|
|
67
|
+
{navigation.canGoBack() && (
|
|
68
|
+
<FAB
|
|
69
|
+
variant="secondary"
|
|
70
|
+
icon="plus"
|
|
71
|
+
onPress={createBusinessBottomSheet.expand}
|
|
72
|
+
/>
|
|
73
|
+
)}
|
|
74
|
+
</View>
|
|
75
|
+
</View>
|
|
76
|
+
<CreateBusinessBottomSheet
|
|
77
|
+
ref={createBusinessBottomSheet.ref}
|
|
78
|
+
close={createBusinessBottomSheet.close}
|
|
79
|
+
/>
|
|
80
|
+
</ParentView>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { DEFAULT_STALE_TIME, queryKeys } from './queryKeys';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
|
|
5
|
+
export const getBusinessData = () => {
|
|
6
|
+
return axios.get('/user/businessData');
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const useBusinesses = () =>
|
|
10
|
+
useQuery([queryKeys.BUSINESSES], getBusinessData, {
|
|
11
|
+
staleTime: DEFAULT_STALE_TIME,
|
|
12
|
+
select: (response) => {
|
|
13
|
+
const businesses = response?.data?.businesses as Array<{
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}>;
|
|
17
|
+
|
|
18
|
+
businesses.sort((b1, b2) => {
|
|
19
|
+
const b1Name = b1.name.toUpperCase();
|
|
20
|
+
const b2Name = b2.name.toUpperCase();
|
|
21
|
+
|
|
22
|
+
if (b1Name < b2Name) {
|
|
23
|
+
return -1;
|
|
24
|
+
}
|
|
25
|
+
if (b1Name > b2Name) {
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
return 0;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return businesses;
|
|
32
|
+
},
|
|
33
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { queryKeys } from './queryKeys';
|
|
3
|
+
import { signUpAPI } from '../auth/api/authentication';
|
|
4
|
+
|
|
5
|
+
export const useCreateBusiness = ({ onSuccess }: { onSuccess: () => void }) => {
|
|
6
|
+
const queryClient = useQueryClient();
|
|
7
|
+
return useMutation(
|
|
8
|
+
async (params: any) => {
|
|
9
|
+
await signUpAPI(params);
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
onSuccess: () => {
|
|
13
|
+
queryClient.invalidateQueries([queryKeys.BUSINESSES]);
|
|
14
|
+
onSuccess();
|
|
15
|
+
},
|
|
16
|
+
}
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
type SnapPoints = Record<string, any>;
|
|
4
|
+
type ValidInitialSnap<T extends SnapPoints> = keyof T;
|
|
5
|
+
|
|
6
|
+
export type TMultiSnapBottomSheetRef<T extends string> = {
|
|
7
|
+
ref: React.MutableRefObject<any>;
|
|
8
|
+
selectedSnap: T;
|
|
9
|
+
snapPoints: {
|
|
10
|
+
[K in T]: string[];
|
|
11
|
+
};
|
|
12
|
+
expand: (snap: T) => void;
|
|
13
|
+
close: () => any;
|
|
14
|
+
selectedSnapPoint: any;
|
|
15
|
+
isVisible: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const useMultiSnapBottomSheetRef = <T extends SnapPoints>({
|
|
19
|
+
initialSnap,
|
|
20
|
+
snapPoints,
|
|
21
|
+
}: {
|
|
22
|
+
initialSnap: ValidInitialSnap<T>;
|
|
23
|
+
snapPoints: T;
|
|
24
|
+
}) => {
|
|
25
|
+
const ref = useRef<any>(null);
|
|
26
|
+
const [selectedSnap, setSelectedSnap] = useState(initialSnap);
|
|
27
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
28
|
+
const expand = (snap: keyof typeof snapPoints) => {
|
|
29
|
+
setSelectedSnap(snap);
|
|
30
|
+
setIsVisible(true);
|
|
31
|
+
ref.current?.expand();
|
|
32
|
+
};
|
|
33
|
+
const close = () => {
|
|
34
|
+
ref.current?.close();
|
|
35
|
+
setIsVisible(false);
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
isVisible,
|
|
39
|
+
ref,
|
|
40
|
+
selectedSnap,
|
|
41
|
+
snapPoints,
|
|
42
|
+
expand,
|
|
43
|
+
close,
|
|
44
|
+
selectedSnapPoint: snapPoints[selectedSnap] ?? snapPoints[0],
|
|
45
|
+
};
|
|
46
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export type TSingleSnapBottomSheetRef = {
|
|
4
|
+
ref: React.MutableRefObject<any>;
|
|
5
|
+
expand: () => void;
|
|
6
|
+
close: () => any;
|
|
7
|
+
isVisible: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const useSingleSnapBottomSheetRef = () => {
|
|
11
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
12
|
+
|
|
13
|
+
const ref = useRef<any>(null);
|
|
14
|
+
const expand = () => {
|
|
15
|
+
ref.current?.expand();
|
|
16
|
+
setIsVisible(true);
|
|
17
|
+
};
|
|
18
|
+
const close = () => {
|
|
19
|
+
setIsVisible(false);
|
|
20
|
+
ref.current?.close();
|
|
21
|
+
};
|
|
22
|
+
return { isVisible, ref, expand, close };
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '@gorhom/bottom-sheet';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Dimensions } from 'react-native';
|
|
2
|
+
import { initialWindowMetrics } from 'react-native-safe-area-context';
|
|
3
|
+
|
|
4
|
+
export const getPercentageFromHeight = (height: number): string => {
|
|
5
|
+
const totalHeight =
|
|
6
|
+
Dimensions.get('window').height -
|
|
7
|
+
(initialWindowMetrics?.insets?.top ?? 0) -
|
|
8
|
+
(initialWindowMetrics?.insets?.bottom ?? 0);
|
|
9
|
+
|
|
10
|
+
return Math.ceil((height / totalHeight) * 100) + '%';
|
|
11
|
+
};
|