@ -1,6 +1,6 @@
import React , { useState , useEffect , useRef , useMemo , useCallback } from 'react' ;
import { List , TouchableRipple , TextInput , Card , Text , Button , useTheme } from 'react-native-paper' ;
import { View , StyleSheet , ScrollView , useWindowDimensions } from 'react-native' ;
import { List , TouchableRipple , TextInput , Card , Text , Button } from 'react-native-paper' ;
import { View , StyleSheet , ScrollView } from 'react-native' ;
import DateTimePicker from '@react-native-community/datetimepicker' ;
import moment from 'moment' ;
import Icon from 'react-native-vector-icons/MaterialCommunityIcons' ;
@ -11,26 +11,12 @@ import {
BottomSheetScrollView
} from '@gorhom/bottom-sheet' ;
import { strings } from '../../../utils/i18n' ;
import { useDispatch , useSelector } from 'react-redux' ;
import { RichEditor , RichToolbar , actions } from 'react-native-pell-rich-editor' ;
import { setIncidentRiskPotential , setRiskLevel , setChronology , setRootCase , setDataPrevention } from '../../../appredux/actions' ;
export default function ChronologyScreen ( { route , navigation } ) {
const theme = useTheme ( ) ;
const isDarkTheme = theme . dark ;
const dispatch = useDispatch ( ) ;
const colorsheet = isDarkTheme ? theme . colors . black : theme . colors . pureWhite ;
const typeRiskIncident = useSelector ( state => state . incidentReportReducer . typeRiskIncident ) ;
const riskLevel = useSelector ( state => state . incidentReportReducer . riskLevel ) ;
const incidentRiskPotential = useSelector ( state => state . incidentReportReducer . incidentRiskPotential ) ;
const chronology = useSelector ( state => state . incidentReportReducer . chronology ) ;
const rootCase = useSelector ( state => state . incidentReportReducer . rootCase ) ;
const dataPrevention = useSelector ( state => state . incidentReportReducer . dataPrevention ) ;
const [ chronology , setChronology ] = useState ( '' )
const [ incidentRiskPotential , setIncidentRiskPotential ] = useState ( { impact : "" , likelihood : "" , value : "" , impactDescription : "" , likelihoodDescription : "" } )
const [ riskLevel , setRiskLevel ] = useState ( { level : "" , backgroundColor : '' , color : '' } )
const bottomSheetModalImpactRef = useRef ( null ) ;
const bottomSheetModalLikelihoodRef = useRef ( null ) ;
const chronologyText = useRef ( ) ;
const rootcaseText = useRef ( ) ;
const snapPoints = useMemo ( ( ) => [ '25%' , '50%' ] , [ ] ) ;
@ -42,20 +28,6 @@ export default function ChronologyScreen({ route, navigation }) {
bottomSheetModalLikelihoodRef . current ? . present ( ) ;
} , [ ] ) ;
// useEffect(() => {
// if (route.params?.isSaved) {
// Toast.show({ type: 'success', text1: 'Berhasil di simpan' }); // Show success toast
// }
// }, [route.params?.isSaved]);
const handleEdit = ( item ) => {
navigation . navigate ( 'ContainedActionScreen' , { item } ) ;
} ;
const handleDelete = ( id ) => {
const updatedData = dataPrevention . filter ( prevention => prevention . id !== id ) ;
dispatch ( setDataPrevention ( updatedData ) ) ;
} ;
useEffect ( ( ) => {
if ( incidentRiskPotential . impact !== "" && incidentRiskPotential . likelihood !== "" ) {
@ -65,39 +37,48 @@ export default function ChronologyScreen({ route, navigation }) {
const val = impactValue * likelihoodValue ;
let newRiskLevel , backgroundColor , color ;
if ( val >= 1 && val <= 5 ) {
backgroundColor = colors . semigreen
color = colors . green
backgroundColor = '#E3F8E8'
color = '#17C13E'
newRiskLevel = 'Rendah' ;
} else if ( val >= 6 && val <= 10 ) {
backgroundColor = colors . yellow
backgroundColor = "#F8DC49"
color = "white"
newRiskLevel = 'Sedang' ;
} else if ( val >= 11 && val <= 15 ) {
backgroundColor = colors . semiRed
color = colors . beanRed
backgroundColor = '#FFD9AF'
color = '#EC9C3D'
newRiskLevel = 'Tinggi' ;
} else {
backgroundColor = colors . red
color = colors . white
backgroundColor = '#FFC5C3'
color = '#D9534F'
newRiskLevel = 'Bencana' ;
}
if ( incidentRiskPotential . value !== val . toString ( ) || riskLevel . level !== newRiskLevel || riskLevel . backgroundColor !== backgroundColor || riskLevel . color !== color ) {
dispatch ( setIncidentRiskPotential ( { ... incidentRiskPotential , value : val . toString ( ) } ) ) ;
dispatch ( setRiskLevel ( { level : newRiskLevel , backgroundColor : backgroundColor , color : color } ) ) ;
setIncidentRiskPotential ( prevState => ( { ... prevState , value : val . toString ( ) } ) ) ;
setRiskLevel ( { level : newRiskLevel , backgroundColor : backgroundColor , color : color } ) ;
}
}
} , [ typeRiskIncident , incidentRiskPotential , riskLevel ] ) ;
} , [ incidentRiskPotential , riskLevel ] ) ;
const handleSelectImpact = ( impact ) => {
dispatch ( setIncidentRiskPotential ( { ... incidentRiskPotential , impact : impact . label , value : impact . value , impactDescription : impact . description } ) ) ;
setIncidentRiskPotential ( prevState => ( {
... prevState ,
impact : impact . label ,
value : impact . value ,
impactDescription : impact . description
} ) ) ;
bottomSheetModalImpactRef . current ? . dismiss ( ) ;
} ;
const handleSelectLikelihood = ( likelihood ) => {
dispatch ( setIncidentRiskPotential ( { ... incidentRiskPotential , likelihood : likelihood . label , likelihoodDescription : likelihood . description } ) ) ;
setIncidentRiskPotential ( prevState => ( {
... prevState ,
likelihood : likelihood . label ,
likelihoodDescription : likelihood . description
} ) ) ;
bottomSheetModalLikelihoodRef . current ? . dismiss ( ) ;
} ;
@ -137,7 +118,6 @@ export default function ChronologyScreen({ route, navigation }) {
< View >
< TouchableRipple key = { dataTranslasiImpact [ data . label ] } onPress = { ( ) => handleSelectImpact ( data ) } >
< List . Item
key = { data . label }
title = { dataTranslasiImpact [ data . label ] }
/ >
< / T o u c h a b l e R i p p l e >
@ -147,77 +127,54 @@ export default function ChronologyScreen({ route, navigation }) {
< View >
< TouchableRipple key = { dataTranslasiLikelihood [ data . label ] } onPress = { ( ) => handleSelectLikelihood ( data ) } >
< List . Item
key = { data . label }
title = { dataTranslasiLikelihood [ data . label ] }
/ >
< / T o u c h a b l e R i p p l e >
< / V i e w >
) ;
return (
< >
< Card style = { { backgroundColor : colors . semiRed , paddingVertical : 15 , paddingHorizontal : 15 , marginHorizontal : 8 , marginVertical : 5 , borderRadius : 5 } } >
< View >
< Text variant = "bodyLarge " style = { { color : colors . beanRed , fontWeight : 'bold' } } >
< Text variant = "bodySmall " style = { { color : colors . beanRed , fontWeight : 'bold' , fontSize : 16 } } >
Kronologis kejadian
< / T e x t >
< Text variant = "bodySmall" style = { { color : colors . beanRed } } >
< Text variant = "bodySmall" style = { { color : colors . beanRed , fontSize : 12 } } >
Jelaskan bagaimana terjadinya insiden
< / T e x t >
< / V i e w >
< / C a r d >
< ScrollView >
< View style = { styles . container } >
< Text variant = "bodyLarge" style = { { color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black } } >
Kronologis Singkat Kejadian
< / T e x t >
< RichEditor
ref = { chronologyText }
placeholder = 'Kronologis Singkat Kejadian'
disabled = { false }
containerStyle = { { backgroundColor : colorsheet , borderWidth : 1 , borderColor : colors . colorsheet } }
initialContentHTML = { chronology }
editorStyle = { { backgroundColor : colorsheet , color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black } }
onChange = { ( text ) => {
dispatch ( setChronology ( text ) ) ;
< TextInput
dense = { true }
underlineColor = { colors . amethystSmoke }
activeOutlineColor = { colors . blue }
label = "Kronologis Singkat Kejadian"
mode = "outlined"
placeholder = 'Isi kronologis'
multiline = { true }
numberOfLines = { 5 }
value = { chronology }
onChangeText = { ( text ) => {
setChronology ( text )
} }
/ >
< RichToolbar
editor = { chronologyText }
actions = { [ actions . setBold , actions . setItalic , actions . setUnderline , actions . insertOrderedList ,
actions . insertBulletsList ] }
iconTint = { isDarkTheme ? theme . colors . pureWhite : theme . colors . black }
selectedIconTint = { isDarkTheme ? theme . colors . pureWhite : theme . colors . black }
selectedButtonStyle = { { backgroundColor : colors . blue } }
style = { { backgroundColor : colorsheet , borderColor : colors . colorsheet , marginBottom : 10 } }
/ >
< Text variant = "bodyLarge" style = { { color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black } } >
Penjelasan Singkat Kejadian
< / T e x t >
< RichEditor
ref = { rootcaseText }
placeholder = 'Kronologis Singkat Kejadian'
disabled = { false }
containerStyle = { { backgroundColor : colorsheet , borderWidth : 1 , borderColor : colors . colorsheet } }
initialContentHTML = { rootCase }
editorStyle = { { backgroundColor : colorsheet , color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black } }
onChange = { ( text ) => {
dispatch ( setRootCase ( text ) ) ;
< TextInput
dense = { true }
underlineColor = { colors . amethystSmoke }
activeOutlineColor = { colors . blue }
mode = "outlined"
label = "Penjelasan Permasalahan"
placeholder = 'Isi Permasalahan'
multiline = { true }
numberOfLines = { 5 }
onChangeText = { ( text ) => {
setChronology ( text )
} }
/ >
< RichToolbar
editor = { rootcaseText }
actions = { [ actions . setBold , actions . setItalic , actions . setUnderline , actions . insertOrderedList ,
actions . insertBulletsList ] }
iconTint = { isDarkTheme ? theme . colors . pureWhite : theme . colors . black }
selectedIconTint = { isDarkTheme ? theme . colors . pureWhite : theme . colors . black }
selectedButtonStyle = { { backgroundColor : colors . blue } }
style = { { backgroundColor : colorsheet , borderColor : colors . colorsheet , marginBottom : 10 } }
/ >
< TouchableRipple onPress = { handleOpenImpact } >
< TextInput
style = { { marginTop : 10 } }
@ -232,8 +189,8 @@ export default function ChronologyScreen({ route, navigation }) {
/ >
< / T o u c h a b l e R i p p l e >
{ incidentRiskPotential . impactDescription && (
< Card style = { { backgroundColor : isDarkTheme ? theme . colors . background : theme . colors . pureWhite , paddingVertical : 15 , paddingHorizontal : 15 , marginVertical : 5 , borderRadius : 5 } } >
< Text variant = "bodySmall" style = { { fontSize : 12 , color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black } } >
< Card style = { { backgroundColor : colors . pureWhite , paddingVertical : 15 , paddingHorizontal : 15 , marginVertical : 5 , borderRadius : 5 } } >
< Text variant = "bodySmall" style = { { fontSize : 12 } } >
{ incidentRiskPotential . impactDescription }
< / T e x t >
< / C a r d >
@ -252,54 +209,50 @@ export default function ChronologyScreen({ route, navigation }) {
< / T o u c h a b l e R i p p l e >
{ incidentRiskPotential . likelihoodDescription && (
< Card style = { { backgroundColor : isDarkTheme ? theme . colors . background : theme . colors . pureWhite , paddingVertical : 15 , paddingHorizontal : 15 , marginVertical : 5 , borderRadius : 5 } } >
< Text variant = "bodySmall" style = { { fontSize : 12 , color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black } } >
< Card style = { { backgroundColor : colors . pureWhite , paddingVertical : 15 , paddingHorizontal : 15 , marginVertical : 5 , borderRadius : 5 } } >
< Text variant = "bodySmall" style = { { fontSize : 12 } } >
{ incidentRiskPotential . likelihoodDescription }
< / T e x t >
< / C a r d >
) }
< View style = { styles . row } >
{ typeRiskIncident &&
< Card style = { { flex : 1 , marginRight : 5 , backgroundColor : typeRiskIncident === 'Critical' ? colors . beanRed : typeRiskIncident === 'Major' ? colors . yellow : 'black' , paddingVertical : 15 , paddingHorizontal : 15 , marginVertical : 5 , borderRadius : 5 } } >
< Text variant = "bodySmall" style = { { fontSize : 12 , color : typeRiskIncident === 'Critical' ? colors . red : typeRiskIncident === 'Major' ? colors . black : 'black' } } >
{ typeRiskIncident }
< / T e x t >
< / C a r d >
}
{ incidentRiskPotential . value && riskLevel . level &&
< Card style = { { flex : 1 , marginLeft : 5 , backgroundColor : riskLevel . backgroundColor , paddingVertical : 15 , paddingHorizontal : 15 , marginVertical : 5 , borderRadius : 5 } } >
< Text variant = "bodySmall" style = { { fontSize : 12 , color : riskLevel . color } } >
{ riskLevel . level } { incidentRiskPotential . value }
< / T e x t >
< / C a r d >
}
< Card style = { { flex : 1 , marginRight : 5 , backgroundColor : '#FFC5C3' , paddingVertical : 15 , paddingHorizontal : 15 , marginVertical : 5 , borderRadius : 5 } } >
< Text variant = "bodySmall" style = { { fontSize : 12 , color : '#D9534F' } } >
Critical
< / T e x t >
< / C a r d >
< Card style = { { flex : 1 , marginLeft : 5 , backgroundColor : riskLevel . backgroundColor , paddingVertical : 15 , paddingHorizontal : 15 , marginVertical : 5 , borderRadius : 5 } } >
< Text variant = "bodySmall" style = { { fontSize : 12 , color : riskLevel . color } } >
{ riskLevel . level } { incidentRiskPotential . value }
< / T e x t >
< / C a r d >
< / V i e w >
< Text variant = "bodySmall" style = { { color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black , fontSize : 14 } } >
< Text variant = "bodySmall" style = { { color : colors . black , fontSize : 14 } } >
Rencana tindakan pencegahan
< / T e x t >
{ dataPrevention . map ( item => (
< Card elevation = { 2 } style = { [ styles . card , { backgroundColor : isDarkTheme ? theme . colors . background : theme . colors . pureWhite } ] } >
< View style = { styles . cardContent } >
< View style = { styles . leftContent } >
< Icon name = "view-list" size = { 25 } color = { colors . blue } / >
< / V i e w >
< View style = { styles . midContent } >
< Text variant = "bodySmall" style = { [ styles . subText , { color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black } ] } > { moment ( item . date ) . format ( 'DD-MM-YYYY' ) } < / T e x t >
< Text variant = "bodyMedium" style = { [ styles . subText , { color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black } ] } > { item . status } < / T e x t >
< Text variant = "headlineMedium" style = { [ styles . Text , { color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black } ] } > { item . who } < / T e x t >
< Text variant = "bodySmall" style = { [ styles . subText , { color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black } ] } > { item . plan } < / T e x t >
< / V i e w >
< Card elevation = { 2 } style = { styles . card } >
< View style = { styles . cardContent } >
< View style = { styles . leftContent } >
< Icon name = "view-list" size = { 25 } color = { colors . blue } / >
< / V i e w >
< View style = { styles . buttonContainer } >
< Button mode = "outlined" style = { styles . button } textColor = { colors . beanRed } onPress = { ( ) => handleEdit ( item ) } >
Edit
< / B u t t o n >
< Button mode = "contained" style = { [ styles . button , { backgroundColor : colors . beanRed } ] } textColor = { isDarkTheme ? theme . colors . black : theme . colors . pureWhite } onPress = { ( ) => handleDelete ( item . id ) } >
Hapus
< / B u t t o n >
< View style = { styles . midContent } >
< Text variant = "bodySmall" style = { styles . subText } > 01 - 03 - 2024 < / T e x t >
< Text variant = "headlineMedium" style = { styles . Text } > Farhan < / T e x t >
< Text variant = "bodySmall" style = { styles . subText } > Melakukan pengamatan dan patroli area pagar luar Depo MRT < / T e x t >
< / V i e w >
< / C a r d >
) ) }
< / V i e w >
< View style = { styles . buttonContainer } >
< Button mode = "outlined" style = { styles . button } textColor = { colors . beanRed } onPress = { ( ) => { navigation . goBack ( ) } } >
Edit
< / B u t t o n >
< Button mode = "contained" style = { [ styles . button , { backgroundColor : colors . beanRed } ] } onPress = { ( ) => console . log ( 'Handle Saved' ) } >
Hapus
< / B u t t o n >
< / V i e w >
< / C a r d >
{ /* color: (typeRiskIncident === 'Critical' ? '#D9534F' : (typeRiskIncident === 'Major' ? '#EC9C3D' : 'black')) */ }
< / V i e w >
< / S c r o l l V i e w >
< Button icon = "plus" style = { { borderRadius : 10 , backgroundColor : colors . semiBlue , marginHorizontal : 8 , } } textColor = { colors . blue } mode = "contained-tonal" onPress = { ( ) => { navigation . navigate ( 'ContainedActionScreen' ) } } >
@ -310,7 +263,6 @@ export default function ChronologyScreen({ route, navigation }) {
ref = { bottomSheetModalImpactRef }
index = { 1 }
snapPoints = { snapPoints }
backgroundStyle = { { backgroundColor : colorsheet } }
>
< BottomSheetScrollView contentContainerStyle = { styles . scrollView } >
{ dataSelectImpact . map ( item => renderImpact ( item ) ) }
@ -322,7 +274,6 @@ export default function ChronologyScreen({ route, navigation }) {
ref = { bottomSheetModalLikelihoodRef }
index = { 1 }
snapPoints = { snapPoints }
backgroundStyle = { { backgroundColor : colorsheet } }
>
< BottomSheetScrollView contentContainerStyle = { styles . scrollView } >
{ dataSelectLikelihood . map ( item => renderLikelihood ( item ) ) }
@ -357,14 +308,17 @@ const styles = StyleSheet.create({
Text : {
fontSize : 16 ,
fontWeight : 'bold' ,
color : colors . blue
} ,
card : {
flex : 1 ,
marginHorizontal : 8 ,
marginVertical : 5 ,
backgroundColor : colors . pureWhite ,
} ,
subText : {
fontSize : 12 ,
color : colors . blue
} ,
row : {
flexDirection : 'row' ,