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,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>