-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: error alert for user displays 🎉
- Loading branch information
1 parent
04da7c1
commit 6002a45
Showing
3 changed files
with
87 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Snackbar } from 'react-native-paper'; | ||
import { | ||
View, Text | ||
} from 'react-native'; | ||
import I18n from '../../../modules/i18n'; | ||
|
||
const ErrorPicker = ({ formikProps, inputs }) => { | ||
const { errors, isSubmitting } = formikProps; | ||
const [formErrors, setFormErrors] = useState([]) | ||
const [visible, setVisible] = useState(false) | ||
|
||
const keysToLabel = (keys) => { | ||
let label = []; | ||
keys.forEach((key) => { | ||
inputs.forEach((input) => { | ||
if (key === input.formikKey) { | ||
label = label.concat([I18n.t(input.label)]); | ||
} | ||
else if (input.fieldType === 'multiInputRowNum') { | ||
input.options.forEach((option) => { | ||
if (key === option.value) { | ||
label = label.concat(I18n.t(option.label)) | ||
} | ||
}) | ||
} | ||
}) | ||
}); | ||
setFormErrors(label.join(", ")); | ||
} | ||
|
||
useEffect(() => { | ||
Object.keys(errors).length > 0 ? setVisible(true) : setVisible(false); | ||
keysToLabel(Object.keys(errors)) | ||
}, [isSubmitting]) | ||
|
||
const dismissSnackBar = () => setVisible(false); | ||
|
||
return ( | ||
<View> | ||
<Snackbar | ||
visible={visible} | ||
onDismiss={dismissSnackBar} | ||
duration={8500} | ||
style={{ | ||
backgroundColor: 'red', | ||
fontSize: 130 | ||
}} | ||
> | ||
<Text style={{ fontSize: 16, fontWeight: 'bold' }}>Inavlid Fields: {"\n\n"}{formErrors}</Text> | ||
</Snackbar> | ||
</View> | ||
) | ||
} | ||
|
||
export default ErrorPicker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters