|
|
@ -1,11 +1,11 @@ |
|
|
|
import { View, Text, StyleSheet, TouchableOpacity, Image, SafeAreaView, StatusBar, Platform } from "react-native"; |
|
|
|
import { View, Text, StyleSheet, TouchableOpacity, Image, SafeAreaView, StatusBar } from "react-native"; |
|
|
|
import BackIcon from "../../components/BackIcon"; |
|
|
|
import BackIcon from "../../components/BackIcon"; |
|
|
|
import fontSize from "../../utils/fontsizeUtils"; |
|
|
|
import fontSize from "../../utils/fontsizeUtils"; |
|
|
|
import { useNavigation, useRoute, RouteProp } from "@react-navigation/native"; |
|
|
|
import { useNavigation, useRoute, RouteProp } from "@react-navigation/native"; |
|
|
|
import { NativeStackNavigationProp } from "@react-navigation/native-stack"; |
|
|
|
import { NativeStackNavigationProp } from "@react-navigation/native-stack"; |
|
|
|
import { RootStackParamList } from "../../navigation/types"; |
|
|
|
import { RootStackParamList } from "../../navigation/types"; |
|
|
|
import { useState, useEffect } from "react"; |
|
|
|
import { useState, useEffect } from "react"; |
|
|
|
import { settingApi, Country } from "../../services/api/setting"; |
|
|
|
import { settingApi } from "../../services/api/setting"; |
|
|
|
import { FlatList } from "react-native"; |
|
|
|
import { FlatList } from "react-native"; |
|
|
|
import flagMap from "../../utils/flagMap"; |
|
|
|
import flagMap from "../../utils/flagMap"; |
|
|
|
import CheckIcon from "../../components/CheckIcon"; |
|
|
|
import CheckIcon from "../../components/CheckIcon"; |
|
|
@ -13,7 +13,10 @@ import Toast from "react-native-toast-message"; |
|
|
|
import { eventBus } from "../../utils/eventBus"; |
|
|
|
import { eventBus } from "../../utils/eventBus"; |
|
|
|
import { changeLanguage } from "../../i18n"; |
|
|
|
import { changeLanguage } from "../../i18n"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import { useTranslation } from "react-i18next"; |
|
|
|
import RNRestart from 'react-native-restart'; |
|
|
|
import { useGlobalStore } from "../../store/useGlobalStore"; |
|
|
|
|
|
|
|
import { userApi } from "../../services/api/userApi"; |
|
|
|
|
|
|
|
import useUserStore from "../../store/user"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Define CountryList type to match API response
|
|
|
|
// Define CountryList type to match API response
|
|
|
@ -30,6 +33,7 @@ type CountryList = { |
|
|
|
|
|
|
|
|
|
|
|
export const CountrySetting = () => { |
|
|
|
export const CountrySetting = () => { |
|
|
|
const { t } = useTranslation(); |
|
|
|
const { t } = useTranslation(); |
|
|
|
|
|
|
|
const { setGlobalCountry, setGlobalCurrency, setGlobalLanguage } = useGlobalStore(); |
|
|
|
const navigation = |
|
|
|
const navigation = |
|
|
|
useNavigation<NativeStackNavigationProp<RootStackParamList>>(); |
|
|
|
useNavigation<NativeStackNavigationProp<RootStackParamList>>(); |
|
|
|
const route = useRoute<RouteProp<RootStackParamList, "CountrySetting">>(); |
|
|
|
const route = useRoute<RouteProp<RootStackParamList, "CountrySetting">>(); |
|
|
@ -40,6 +44,8 @@ export const CountrySetting = () => { |
|
|
|
const [country, setCountry] = useState<number>(0); |
|
|
|
const [country, setCountry] = useState<number>(0); |
|
|
|
const [currency, setCurrency] = useState<string>(""); |
|
|
|
const [currency, setCurrency] = useState<string>(""); |
|
|
|
const [language, setLanguage] = useState<string>(""); |
|
|
|
const [language, setLanguage] = useState<string>(""); |
|
|
|
|
|
|
|
const { setUser } = useUserStore(); |
|
|
|
|
|
|
|
|
|
|
|
const getCountry = async () => { |
|
|
|
const getCountry = async () => { |
|
|
|
const res = await settingApi.getCountryList(); |
|
|
|
const res = await settingApi.getCountryList(); |
|
|
|
setCountryList(res);
|
|
|
|
setCountryList(res);
|
|
|
@ -67,15 +73,17 @@ export const CountrySetting = () => { |
|
|
|
const putSettinghandel = async () => { |
|
|
|
const putSettinghandel = async () => { |
|
|
|
// Only include the property that corresponds to the active tab
|
|
|
|
// Only include the property that corresponds to the active tab
|
|
|
|
let data = {}; |
|
|
|
let data = {}; |
|
|
|
|
|
|
|
if (changeType === "country") {
|
|
|
|
if (changeType === "country") { |
|
|
|
|
|
|
|
data = { country: country }; |
|
|
|
data = { country: country }; |
|
|
|
|
|
|
|
setGlobalCountry({ country: country.toString() }); |
|
|
|
} else if (changeType === "currency") { |
|
|
|
} else if (changeType === "currency") { |
|
|
|
data = { currency: currency }; |
|
|
|
data = { currency: currency }; |
|
|
|
|
|
|
|
setGlobalCurrency({ currency: currency }); |
|
|
|
} else if (changeType === "language") { |
|
|
|
} else if (changeType === "language") { |
|
|
|
data = { language: language }; |
|
|
|
data = { language: language }; |
|
|
|
|
|
|
|
setGlobalLanguage({ language: language }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Toast.show({ |
|
|
|
Toast.show({ |
|
|
|
text1: t('setting.success'), |
|
|
|
text1: t('setting.success'), |
|
|
|
type: "success", |
|
|
|
type: "success", |
|
|
@ -86,8 +94,8 @@ export const CountrySetting = () => { |
|
|
|
await changeLanguage(language); |
|
|
|
await changeLanguage(language); |
|
|
|
} |
|
|
|
} |
|
|
|
eventBus.emit("refreshSetting"); |
|
|
|
eventBus.emit("refreshSetting"); |
|
|
|
|
|
|
|
const userData = await userApi.getProfile(); |
|
|
|
RNRestart.Restart(); |
|
|
|
setUser(userData); |
|
|
|
}; |
|
|
|
}; |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<SafeAreaView style={styles.safeArea}> |
|
|
|
<SafeAreaView style={styles.safeArea}> |
|
|
|