added notification

This commit is contained in:
Samandar Turgunboyev
2025-09-04 10:06:46 +05:00
parent e51ff4f502
commit f55a3a50ed
54 changed files with 2502 additions and 643 deletions

View File

@@ -1,6 +1,7 @@
import Clipboard from '@react-native-clipboard/clipboard';
import { useQuery } from '@tanstack/react-query';
import { authApi } from 'api/auth';
import warhouses_api from 'api/warhouses';
import React from 'react';
import { useTranslation } from 'react-i18next';
import {
@@ -53,9 +54,8 @@ const TabsAutoWarehouses = () => {
];
const handleCopy = (info: string[]) => {
if (getMe?.status === 'active') {
const textToCopy = info.join('\n');
Clipboard.setString(textToCopy);
if (getMe?.status === 'ACTIVE') {
Clipboard.setString(info.join('\n'));
Toast.show({
type: 'success',
text1: t('Nusxa olingan'),
@@ -74,39 +74,50 @@ const TabsAutoWarehouses = () => {
}
};
const { data } = useQuery({
queryKey: ['warhouses'],
queryFn: () => warhouses_api.getWarhouses({ cargoType: 'AUTO' }),
});
const formattedData =
data?.map((item: string | null) => {
if (!item) return '';
const withAutoCargo = item.replace('%s', getMe?.autoCargoId || '');
const withAviaCargo = withAutoCargo.replace(
'%s',
getMe?.aviaCargoId || '',
);
return withAviaCargo;
}) || [];
return (
<FlatList
data={addressInfo}
data={formattedData}
horizontal
keyExtractor={item => item.id.toString()}
keyExtractor={(_, index) => index.toString()}
pagingEnabled
showsHorizontalScrollIndicator={false}
snapToInterval={cardWidth + 10}
decelerationRate="fast"
renderItem={({ item, index }) => {
const isLast = index === addressInfo.length - 1;
const isLast = index === formattedData.length - 1;
return (
<View style={[styles.card, { marginRight: isLast ? 0 : 10 }]}>
<View style={styles.titleCard}>
<Kitay width={24 * scale} height={24 * scale} />
<Text style={styles.title}>{item.title}</Text>
<Text style={styles.title}>China (Auto)</Text>
</View>
<View style={styles.infoId}>
<View style={{ gap: 4 * scale, width: '90%' }}>
{item.addressInfo.map((line, idx) => (
<Text key={idx} style={styles.infoText}>
{line}
</Text>
))}
<Text style={styles.infoText}>{item}</Text>
</View>
<TouchableOpacity onPress={() => handleCopy(item.addressInfo)}>
<Copy color="#28A7E8" width={24 * scale} height={24 * scale} />
</TouchableOpacity>
</View>
<View style={styles.postCodeWrapper}>
<Text style={styles.postCodeText}>{t('Auto post kodi')}: </Text>
<Text style={styles.postCode}>{item.postCode}</Text>
</View>
</View>
);
}}
@@ -117,7 +128,6 @@ const TabsAutoWarehouses = () => {
const makeStyles = (scale: number, cardWidth: number, screenWidth: number) =>
StyleSheet.create({
card: {
height: '100%',
width: cardWidth,
backgroundColor: '#28a8e82c',
borderRadius: 12 * scale,

View File

@@ -1,6 +1,7 @@
import Clipboard from '@react-native-clipboard/clipboard';
import { useQuery } from '@tanstack/react-query';
import { authApi } from 'api/auth';
import warhouses_api from 'api/warhouses';
import React from 'react';
import { useTranslation } from 'react-i18next';
import {
@@ -53,13 +54,12 @@ const TabsAviaWarehouses = () => {
const { t } = useTranslation();
const handleCopy = (info: string[]) => {
if (getMe?.status === 'active') {
const textToCopy = info.join('\n');
Clipboard.setString(textToCopy);
if (getMe?.status === 'ACTIVE') {
Clipboard.setString(info.join('\n'));
Toast.show({
type: 'success',
text1: t('Nusxa olingan'),
text2: t('Avia manzili nusxalandi!'),
text2: t('Avto manzili nusxalandi!'),
position: 'top',
visibilityTime: 2000,
});
@@ -74,39 +74,50 @@ const TabsAviaWarehouses = () => {
}
};
const { data } = useQuery({
queryKey: ['warhouses'],
queryFn: () => warhouses_api.getWarhouses({ cargoType: 'AVIA' }),
});
const formattedData =
data?.map((item: string | null) => {
if (!item) return '';
const withAutoCargo = item.replace('%s', getMe?.autoCargoId || '');
const withAviaCargo = withAutoCargo.replace(
'%s',
getMe?.aviaCargoId || '',
);
return withAviaCargo;
}) || [];
return (
<FlatList
data={addressList}
data={formattedData}
horizontal
keyExtractor={item => item.id.toString()}
keyExtractor={(_, index) => index.toString()}
pagingEnabled
showsHorizontalScrollIndicator={false}
snapToInterval={cardWidth + 10} // +10: marginRight
snapToInterval={cardWidth + 10}
decelerationRate="fast"
renderItem={({ item, index }) => {
const isLast = index === addressList.length - 1;
const isLast = index === formattedData.length - 1;
return (
<View style={[styles.card, { marginRight: isLast ? 0 : 10 }]}>
<View style={styles.titleCard}>
<Kitay width={24 * scale} height={24 * scale} />
<Text style={styles.title}>{item.title}</Text>
<Text style={styles.title}>China (Auto)</Text>
</View>
<View style={styles.infoId}>
<View style={{ gap: 4 * scale }}>
{item.addressInfo.map((line, idx) => (
<Text key={idx} style={styles.infoText}>
{line}
</Text>
))}
<View style={{ gap: 4 * scale, width: '90%' }}>
<Text style={styles.infoText}>{item}</Text>
</View>
<TouchableOpacity onPress={() => handleCopy(item.addressInfo)}>
<Copy color="#28A7E8" width={24 * scale} height={24 * scale} />
</TouchableOpacity>
</View>
<View style={styles.postCodeWrapper}>
<Text style={styles.postCodeText}>{t('Avia post kodi')}: </Text>
<Text style={styles.postCode}>{item.postCode}</Text>
</View>
</View>
);
}}
@@ -116,26 +127,7 @@ const TabsAviaWarehouses = () => {
const makeStyles = (scale: number, cardWidth: number, screenWidth: number) =>
StyleSheet.create({
container: {
height: 200,
width: '95%',
backgroundColor: '#28a8e82c',
margin: 'auto',
marginTop: 20,
borderRadius: 12,
padding: 12,
gap: 10,
},
scrollContainer: {
marginTop: 20,
paddingHorizontal: (screenWidth - cardWidth) / 2,
},
postCodeWrapper: {
flexDirection: 'row',
alignItems: 'center',
},
card: {
height: 220 * scale,
width: cardWidth,
backgroundColor: '#28a8e82c',
borderRadius: 12 * scale,
@@ -144,31 +136,37 @@ const makeStyles = (scale: number, cardWidth: number, screenWidth: number) =>
},
titleCard: {
flexDirection: 'row',
gap: 8,
gap: 8 * scale,
alignItems: 'center',
},
title: {
fontSize: 20,
fontSize: 20 * scale,
fontWeight: '600',
color: '#101623CC',
},
infoId: {
flexDirection: 'row',
justifyContent: 'space-between',
marginVertical: 8 * scale,
},
infoText: {
fontSize: 16,
fontSize: 16 * scale,
color: '#28A7E8',
},
postCodeWrapper: {
flexDirection: 'row',
alignItems: 'center',
},
postCodeText: {
fontSize: 16,
fontSize: 16 * scale,
color: '#000000',
fontWeight: '500',
},
postCode: {
fontSize: 16,
fontSize: 16 * scale,
color: '#28A7E8',
fontWeight: '400',
marginLeft: 4 * scale,
},
});

View File

@@ -1,8 +1,12 @@
import { useQuery } from '@tanstack/react-query';
import { authApi } from 'api/auth';
import SingleFileDrop from 'components/FileDrop';
import LayoutTwo from 'components/LayoutTwo';
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import {
ActivityIndicator,
Image,
RefreshControl,
ScrollView,
StyleSheet,
@@ -10,14 +14,71 @@ import {
TouchableOpacity,
View,
} from 'react-native';
import Toast from 'react-native-toast-message';
import Shablon from 'screens/../../assets/bootsplash/shablon.jpg';
import TabsAutoWarehouses from './TabsAutoWarehouses';
import TabsAviaWarehouses from './TabsAviaWarehouses';
interface FileData {
uri: string;
name: string;
type: string;
base64: string;
}
interface WarehousesProps {}
const botToken = '7768577881:AAGXGtOl2IiMImrsY6BZmksN9Rjeq2InlTo';
const Warehouses = (props: WarehousesProps) => {
const [refreshing, setRefreshing] = React.useState(false);
const { t } = useTranslation();
const [isLoading, setIsLoading] = React.useState(false);
const [backImage, setBackImage] = React.useState<FileData | null>(null);
const { data: getMe } = useQuery({
queryKey: ['getMe'],
queryFn: authApi.getMe,
});
const openTelegramWithImage = async () => {
const telegramApiUrl = `https://api.telegram.org/bot${botToken}/sendPhoto`;
const formData = new FormData();
formData.append('chat_id', '-1002950892822');
formData.append('photo', {
uri: backImage?.uri,
type: 'image/jpeg',
name: 'photo.jpg',
});
formData.append(
'caption',
`Foydalanuvchi ismi: ${getMe?.fullName}
Telefon nomer: +${getMe?.phone}
Cargo Idsi: ${getMe?.aviaCargoId}
`,
);
try {
setIsLoading(true);
await fetch(telegramApiUrl, {
method: 'POST',
body: formData,
});
Toast.show({
type: 'success',
text1: t("So'rovingiz jo'natilidi. Tez orada siz bilan bog'lanamiz"),
position: 'top',
visibilityTime: 2000,
});
} catch (error) {
Toast.show({
type: 'error',
text1: t('Xatolik yuz berdi'),
position: 'top',
visibilityTime: 2000,
});
} finally {
setIsLoading(false); // 👈 loading tugadi
}
};
const onRefresh = React.useCallback(() => {
setRefreshing(true);
@@ -72,9 +133,25 @@ const Warehouses = (props: WarehousesProps) => {
</Text>
</View>
<Text style={styles.title}>{t('Skrenshot rasmini yuklang')}</Text>
<SingleFileDrop title={t('Rasmni shu yerga yuklang')} />
<TouchableOpacity style={styles.button}>
<Text style={styles.btnText}>{t('Manzilni tekshirish')}</Text>
<Image
source={Shablon}
style={{ width: '100%', height: 500, objectFit: 'cover' }}
/>
<SingleFileDrop
title={t('Rasmni shu yerga yuklang')}
onFileSelected={setBackImage}
type="image/*"
/>
<TouchableOpacity
style={[styles.button, isLoading && { opacity: 0.7 }]}
onPress={openTelegramWithImage}
disabled={isLoading}
>
{isLoading ? (
<ActivityIndicator size="small" color="#fff" />
) : (
<Text style={styles.btnText}>{t('Manzilni tekshirish')}</Text>
)}
</TouchableOpacity>
</View>
</ScrollView>