Skip to content

Commit

Permalink
if toggle is active, the button is displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
doljko committed Mar 18, 2024
1 parent 564775f commit 5c024a5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 37 deletions.
32 changes: 22 additions & 10 deletions src/features/Shared/EntityScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const EntityScreen = ({ navigation, route }) => {
const isMounted = useMountedState();
const actionSheetRef = createRef();
const fleetbase = useFleetbase();
const internalInstance = useFleetbase('int/v1');
const [locale] = useLocale();

const [order, setOrder] = useState(new Order(_order, fleetbase.getAdapter()));
const [entity, setEntity] = useState(new Entity(_entity, fleetbase.getAdapter()));
const [isEntityFieldsEditable, setEntityFieldsEditable] = useState();
const [isLoading, setIsLoading] = useState(false);
const [isRefreshing, setIsRefreshing] = useState(false);

Expand All @@ -49,6 +51,14 @@ const EntityScreen = ({ navigation, route }) => {
});
};

useEffect(() => {
const adapter = internalInstance.getAdapter();
adapter.get('fleet-ops/settings/entity-editing-settings').then(res => {
const editableEntityFields = res.isEntityFieldsEditable;
setEntityFieldsEditable(editableEntityFields);
});
});

return (
<View style={[tailwind('bg-gray-800 h-full')]}>
<View style={[tailwind('z-50 bg-gray-800 border-b border-gray-900 shadow-lg')]}>
Expand Down Expand Up @@ -301,16 +311,18 @@ const EntityScreen = ({ navigation, route }) => {
</View>
</View>
</View>
<TouchableOpacity
onPress={() => {
navigation.navigate('SettingsScreen', { data: entity.getAttributes() });
}}
disabled={isLoading}
style={tailwind('flex py-2 px-2')}>
<View style={tailwind('btn bg-gray-900 border border-gray-700 mt-6 ')}>
<Text style={tailwind('font-semibold text-lg text-gray-50 text-center')}>{translate('Core.SettingsScreen.update')}</Text>
</View>
</TouchableOpacity>
{isEntityFieldsEditable ? (
<TouchableOpacity
onPress={() => {
navigation.navigate('SettingsScreen', { data: entity.getAttributes() });
}}
disabled={isLoading}
style={tailwind('flex py-2 px-2')}>
<View style={tailwind('btn bg-gray-900 border border-gray-700 mt-6 ')}>
<Text style={tailwind('font-semibold text-lg text-gray-50 text-center')}>{translate('Core.SettingsScreen.update')}</Text>
</View>
</TouchableOpacity>
) : null}
</View>
</View>
</ScrollView>
Expand Down
53 changes: 26 additions & 27 deletions src/features/Shared/SettingsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,33 @@ const SettingsScreen = ({ route }) => {
const saveEntitySettings = () => {
setIsLoading(true);
const adapter = fleetbase.getAdapter();
{
adapter
.put(`entities/${routeParam.data.id}`, {
name: value?.name,
description: value?.description,
sku: value?.sku,
height: value?.height,
width: value?.width,
length: value?.length,
weight: value?.weight,
declared_value: value?.declared_value,
sale_price: value?.sale_price,
})
.then(() => {
Toast.show({
type: 'success',
text1: `Successfully updated`,
});
setIsLoading(false);
// Refresh data here
fetchSettings();
navigation.goBack();
})
.catch(error => {
setIsLoading(false);
logError(error);
adapter
.put(`entities/${routeParam.data.id}`, {
name: value?.name,
description: value?.description,
sku: value?.sku,
height: value?.height,
width: value?.width,
length: value?.length,
weight: value?.weight,
declared_value: value?.declared_value,
sale_price: value?.sale_price,
})
.then(() => {
Toast.show({
type: 'success',
text1: `Successfully updated`,
});
}

setIsLoading(false);
fetchSettings();

navigation.goBack();
})
.catch(error => {
setIsLoading(false);
logError(error);
});
};

return (
Expand Down

0 comments on commit 5c024a5

Please sign in to comment.