|
|
@@ -24,6 +24,7 @@ import { qualityOptions } from '../utils/constants';
|
|
|
import { styles } from './styles';
|
|
|
|
|
|
import CalendarSvg from '../../../../../assets/icons/calendar.svg';
|
|
|
+import { ActivityIndicator } from 'react-native-paper';
|
|
|
|
|
|
interface DateValue {
|
|
|
year: number | null;
|
|
|
@@ -57,6 +58,7 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
const [description, setDescription] = useState<string>('');
|
|
|
const [regions, setRegions] = useState<RegionWithDates[] | null>(null);
|
|
|
const [disabled, setDisabled] = useState(true);
|
|
|
+ const [isLoading, setIsLoading] = useState<string | null>(null);
|
|
|
const [qualitySelectorVisible, setQualitySelectorVisible] = useState(false);
|
|
|
const [selectedRegionId, setSelectedRegionId] = useState<number | null>(null);
|
|
|
const [isWarningModalVisible, setIsWarningModalVisible] = useState(false);
|
|
|
@@ -347,6 +349,7 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
|
|
|
const handleSaveNewTrip = () => {
|
|
|
if (regions && selectedDates) {
|
|
|
+ setIsLoading('save');
|
|
|
const regionsData = regions.map((region) => {
|
|
|
return {
|
|
|
id: region.id,
|
|
|
@@ -370,8 +373,14 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
regions: regionsData
|
|
|
},
|
|
|
{
|
|
|
- onSuccess: () => {
|
|
|
- navigation.popTo(...([NAVIGATION_PAGES.TRIPS, { saved: true }] as never));
|
|
|
+ onSuccess: (res) => {
|
|
|
+ if (res && res.result === 'OK') {
|
|
|
+ navigation.popTo(...([NAVIGATION_PAGES.TRIPS, { saved: true }] as never));
|
|
|
+ }
|
|
|
+ setIsLoading(null);
|
|
|
+ },
|
|
|
+ onError: () => {
|
|
|
+ setIsLoading(null);
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
@@ -382,6 +391,7 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
if (regions && selectedDates) {
|
|
|
const isStartDateInFuture =
|
|
|
selectedDates.split(' - ')[0] > new Date().toISOString().split('T')[0];
|
|
|
+ setIsLoading('update');
|
|
|
const regionsData = regions.map((region) => {
|
|
|
return {
|
|
|
id: region.id,
|
|
|
@@ -407,7 +417,13 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
},
|
|
|
{
|
|
|
onSuccess: (res) => {
|
|
|
- navigation.popTo(...([NAVIGATION_PAGES.TRIPS, { updated: true }] as never));
|
|
|
+ if (res && res.result === 'OK') {
|
|
|
+ navigation.popTo(...([NAVIGATION_PAGES.TRIPS, { updated: true }] as never));
|
|
|
+ }
|
|
|
+ setIsLoading(null);
|
|
|
+ },
|
|
|
+ onError: () => {
|
|
|
+ setIsLoading(null);
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
@@ -488,8 +504,13 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
<TouchableOpacity
|
|
|
style={[styles.tabStyle, styles.deleteTab]}
|
|
|
onPress={() => setIsWarningModalVisible(true)}
|
|
|
+ disabled={isLoading === 'delete'}
|
|
|
>
|
|
|
- <Text style={[styles.tabText, styles.deleteTabText]}>Delete Trip</Text>
|
|
|
+ {isLoading === 'delete' ? (
|
|
|
+ <ActivityIndicator size={18} color={Colors.RED} />
|
|
|
+ ) : (
|
|
|
+ <Text style={[styles.tabText, styles.deleteTabText]}>Delete Trip</Text>
|
|
|
+ )}
|
|
|
</TouchableOpacity>
|
|
|
<TouchableOpacity
|
|
|
style={[
|
|
|
@@ -498,9 +519,13 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
disabled && { backgroundColor: Colors.LIGHT_GRAY, borderColor: Colors.LIGHT_GRAY }
|
|
|
]}
|
|
|
onPress={handleUpdateTrip}
|
|
|
- disabled={disabled}
|
|
|
+ disabled={disabled || isLoading === 'update'}
|
|
|
>
|
|
|
- <Text style={[styles.tabText, styles.addNewTabText]}>Save Trip</Text>
|
|
|
+ {isLoading === 'update' ? (
|
|
|
+ <ActivityIndicator size={18} color={Colors.WHITE} />
|
|
|
+ ) : (
|
|
|
+ <Text style={[styles.tabText, styles.addNewTabText]}>Save Trip</Text>
|
|
|
+ )}
|
|
|
</TouchableOpacity>
|
|
|
</>
|
|
|
) : (
|
|
|
@@ -512,9 +537,13 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
{ paddingVertical: 12 }
|
|
|
]}
|
|
|
onPress={handleSaveNewTrip}
|
|
|
- disabled={disabled}
|
|
|
+ disabled={disabled || isLoading === 'save'}
|
|
|
>
|
|
|
- <Text style={[styles.tabText, styles.addNewTabText]}>Add New Trip</Text>
|
|
|
+ {isLoading === 'save' ? (
|
|
|
+ <ActivityIndicator size={18} color={Colors.WHITE} />
|
|
|
+ ) : (
|
|
|
+ <Text style={[styles.tabText, styles.addNewTabText]}>Add New Trip</Text>
|
|
|
+ )}
|
|
|
</TouchableOpacity>
|
|
|
)}
|
|
|
</View>
|
|
|
@@ -637,14 +666,21 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
onModalHide={() => {
|
|
|
if (pendingDelete) {
|
|
|
setPendingDelete(false);
|
|
|
+ setIsLoading('delete');
|
|
|
deleteTrip(
|
|
|
{
|
|
|
token,
|
|
|
trip_id: editTripId
|
|
|
},
|
|
|
{
|
|
|
- onSuccess: () => {
|
|
|
- navigation.popTo(...([NAVIGATION_PAGES.TRIPS, { deleted: true }] as never));
|
|
|
+ onSuccess: (res) => {
|
|
|
+ if (res && res.result === 'OK') {
|
|
|
+ navigation.popTo(...([NAVIGATION_PAGES.TRIPS, { deleted: true }] as never));
|
|
|
+ }
|
|
|
+ setIsLoading(null);
|
|
|
+ },
|
|
|
+ onError: () => {
|
|
|
+ setIsLoading(null);
|
|
|
}
|
|
|
}
|
|
|
);
|