enabling alert for disabled button in tab group

This commit is contained in:
wunderfisch
2024-02-28 13:06:25 +01:00
parent 661abc8aee
commit ad47b4bee0
2 changed files with 19 additions and 2 deletions
+14 -2
View File
@@ -1,6 +1,6 @@
import React from 'react' import React from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { StyleSheet, TouchableOpacity, View } from 'react-native' import { Alert, StyleSheet, TouchableOpacity, View } from 'react-native'
import AppText from '../common/app-text' import AppText from '../common/app-text'
@@ -19,6 +19,16 @@ export default function SelectTabGroup({
const isSecondarySymptomSwitch = const isSecondarySymptomSwitch =
buttons[0]['label'] === labels.secondarySymptom.mucus buttons[0]['label'] === labels.secondarySymptom.mucus
// Disable is only used for secondarySymptom in customization, if more come up maybe consider more tidy solution
const showDisableAlert = (label) => {
if (label === 'cervix' || 'mucus') {
Alert.alert(
labels.secondarySymptom.disabled.title,
labels.secondarySymptom.disabled.message
)
}
}
return ( return (
<View style={styles.container}> <View style={styles.container}>
{buttons.map(({ label, value }, i) => { {buttons.map(({ label, value }, i) => {
@@ -40,7 +50,9 @@ export default function SelectTabGroup({
return ( return (
<TouchableOpacity <TouchableOpacity
onPress={() => !disabled && onSelect(value)} onPress={() =>
!disabled ? onSelect(value) : showDisableAlert(label)
}
key={i} key={i}
style={boxStyle} style={boxStyle}
> >
@@ -148,7 +148,12 @@ const Settings = () => {
if (isMucusTrackingCategoryEnabled && isCervixTrackingCategoryEnabled) { if (isMucusTrackingCategoryEnabled && isCervixTrackingCategoryEnabled) {
setUseCervixAsSecondarySymptom(value) setUseCervixAsSecondarySymptom(value)
saveUseCervixAsSecondarySymptom(value) saveUseCervixAsSecondarySymptom(value)
console.log('show SecSymp value :>> ', value)
} else if (!isFertilityTrackingEnabled) {
console.log('2 show SecSymp value :>> ', value)
secondarySymptomDisabledPrompt()
} else { } else {
console.log('3 show SecSymp value :>> ', value)
secondarySymptomDisabledPrompt() secondarySymptomDisabledPrompt()
} }
} }