In order to display error messages in my app, I have created the following code:
function createTimer(): void {
if (!timer.start) {
Alert.alert(strings.reminders['date-required'])
return;
} else if (!timer.end) {
Alert.alert(strings.reminders['date-required'])
return;
}
let curTimer = timer;
curTimer.task = currentTask
setCreateLoading(true)
timerService.create(curTimer).then(() => {
setCreateLoading(false);
Alert.alert(strings.alert.success, '', [
{ text: strings.button.ok, onPress: () => closeNewTimerModal() }
],
{ cancelable: false }
)
}).catch(e => {
let message: string;
if(e.code == Error.TIMER_INTERVALS_INTERSECT) {
message = strings['time-tracking']['time-intervals-intersect']
}
else if(e.code == Error.START_DATE_IS_AFTER_END_DATE) {
message = strings['time-tracking']['start-after-end']
}
else if(e.code == Error.END_DATE_IS_AFTER_NOW) {
message = strings['time-tracking']['end-after-now']
}
else if(e.code == Error.TASK_IS_ARCHIVED) {
message = strings['time-tracking']['task-archived']
}
Alert.alert(message)
setCreateLoading(false);
})
However, I am having trouble with the alert
function and the message
parameter. When I try to use it as strings.message.something
, there seems to be an error. I believe it should be:
Alert.alert(strings.message.something)
but I cannot find the exact value for something
. Simply using Alert.alert(strings.message)
opens the popup without any error message.