@ -1,6 +1,6 @@
import React , { useState , useEffect , useRef , useMemo , useCallback } from 'react' ;
import { List , TouchableRipple , TextInput , Card , Text , Button } from 'react-native-paper' ;
import { View , StyleSheet , ScrollView } from 'react-native' ;
import { List , TouchableRipple , TextInput , Card , Text , Button , useTheme } from 'react-native-paper' ;
import { View , StyleSheet , ScrollView , useWindowDimensions } from 'react-native' ;
import DateTimePicker from '@react-native-community/datetimepicker' ;
import moment from 'moment' ;
import Icon from 'react-native-vector-icons/MaterialCommunityIcons' ;
@ -11,12 +11,26 @@ 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 [ chronology , setChronology ] = useState ( '' )
const [ incidentRiskPotential , setIncidentRiskPotential ] = useState ( { impact : "" , likelihood : "" , value : "" , impactDescription : "" , likelihoodDescription : "" } )
const [ riskLevel , setRiskLevel ] = useState ( { level : "" , backgroundColor : '' , color : '' } )
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 bottomSheetModalImpactRef = useRef ( null ) ;
const bottomSheetModalLikelihoodRef = useRef ( null ) ;
const chronologyText = useRef ( ) ;
const rootcaseText = useRef ( ) ;
const snapPoints = useMemo ( ( ) => [ '25%' , '50%' ] , [ ] ) ;
@ -28,6 +42,20 @@ 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 !== "" ) {
@ -37,48 +65,39 @@ export default function ChronologyScreen({ route, navigation }) {
const val = impactValue * likelihoodValue ;
let newRiskLevel , backgroundColor , color ;
if ( val >= 1 && val <= 5 ) {
backgroundColor = '#E3F8E8'
color = '#17C13E'
backgroundColor = colors . semigreen
color = colors . green
newRiskLevel = 'Rendah' ;
} else if ( val >= 6 && val <= 10 ) {
backgroundColor = "#F8DC49"
backgroundColor = colors . yellow
color = "white"
newRiskLevel = 'Sedang' ;
} else if ( val >= 11 && val <= 15 ) {
backgroundColor = '#FFD9AF'
color = '#EC9C3D'
backgroundColor = colors . semiRed
color = colors . beanRed
newRiskLevel = 'Tinggi' ;
} else {
backgroundColor = '#FFC5C3'
color = '#D9534F'
backgroundColor = colors . red
color = colors . white
newRiskLevel = 'Bencana' ;
}
if ( incidentRiskPotential . value !== val . toString ( ) || riskLevel . level !== newRiskLevel || riskLevel . backgroundColor !== backgroundColor || riskLevel . color !== color ) {
setIncidentRiskPotential ( prevState => ( { ... prevState , value : val . toString ( ) } ) ) ;
setRiskLevel ( { level : newRiskLevel , backgroundColor : backgroundColor , color : color } ) ;
dispatch ( setIncidentRiskPotential ( { ... incidentRiskPotential , value : val . toString ( ) } ) ) ;
dispatch ( setRiskLevel ( { level : newRiskLevel , backgroundColor : backgroundColor , color : color } ) ) ;
}
}
} , [ incidentRiskPotential , riskLevel ] ) ;
} , [ typeRiskIncident , incidentRiskPotential , riskLevel ] ) ;
const handleSelectImpact = ( impact ) => {
setIncidentRiskPotential ( prevState => ( {
... prevState ,
impact : impact . label ,
value : impact . value ,
impactDescription : impact . description
} ) ) ;
dispatch ( setIncidentRiskPotential ( { ... incidentRiskPotential , impact : impact . label , value : impact . value , impactDescription : impact . description } ) ) ;
bottomSheetModalImpactRef . current ? . dismiss ( ) ;
} ;
const handleSelectLikelihood = ( likelihood ) => {
setIncidentRiskPotential ( prevState => ( {
... prevState ,
likelihood : likelihood . label ,
likelihoodDescription : likelihood . description
} ) ) ;
dispatch ( setIncidentRiskPotential ( { ... incidentRiskPotential , likelihood : likelihood . label , likelihoodDescription : likelihood . description } ) ) ;
bottomSheetModalLikelihoodRef . current ? . dismiss ( ) ;
} ;
@ -118,6 +137,7 @@ 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 >
@ -127,54 +147,77 @@ 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 = "bodySmall " style = { { color : colors . beanRed , fontWeight : 'bold' , fontSize : 16 } } >
< Text variant = "bodyLarge " style = { { color : colors . beanRed , fontWeight : 'bold' } } >
Kronologis kejadian
< / T e x t >
< Text variant = "bodySmall" style = { { color : colors . beanRed , fontSize : 12 } } >
< Text variant = "bodySmall" style = { { color : colors . beanRed } } >
Jelaskan bagaimana terjadinya insiden
< / T e x t >
< / V i e w >
< / C a r d >
< ScrollView >
< View style = { styles . container } >
< 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 )
< 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 }
mode = "outlined"
label = "Penjelasan Permasalahan"
placeholder = 'Isi Permasalahan'
multiline = { true }
numberOfLines = { 5 }
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 ) ) ;
} }
/ >
< 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 } }
@ -189,8 +232,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 : colors . pureWhite , paddingVertical : 15 , paddingHorizontal : 15 , marginVertical : 5 , borderRadius : 5 } } >
< Text variant = "bodySmall" style = { { fontSize : 12 } } >
< 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 } } >
{ incidentRiskPotential . impactDescription }
< / T e x t >
< / C a r d >
@ -209,50 +252,54 @@ 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 : colors . pureWhite , paddingVertical : 15 , paddingHorizontal : 15 , marginVertical : 5 , borderRadius : 5 } } >
< Text variant = "bodySmall" style = { { fontSize : 12 } } >
< 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 } } >
{ incidentRiskPotential . likelihoodDescription }
< / T e x t >
< / C a r d >
) }
< View style = { styles . row } >
< 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 >
{ 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 >
}
< / V i e w >
< Text variant = "bodySmall" style = { { color : colors . black , fontSize : 14 } } >
< Text variant = "bodySmall" style = { { color : isDarkTheme ? theme . colors . pureWhite : theme . colors . black , fontSize : 14 } } >
Rencana tindakan pencegahan
< / T e x t >
< Card elevation = { 2 } style = { styles . card } >
< View style = { styles . cardContent } >
< View style = { styles . leftContent } >
< Icon name = "view-list" size = { 25 } color = { colors . blue } / >
{ 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 >
< / V i e w >
< 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 >
< 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 >
< / V i e w >
< / 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')) */ }
< / C a r d >
) ) }
< / 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' ) } } >
@ -263,6 +310,7 @@ export default function ChronologyScreen({ route, navigation }) {
ref = { bottomSheetModalImpactRef }
index = { 1 }
snapPoints = { snapPoints }
backgroundStyle = { { backgroundColor : colorsheet } }
>
< BottomSheetScrollView contentContainerStyle = { styles . scrollView } >
{ dataSelectImpact . map ( item => renderImpact ( item ) ) }
@ -274,6 +322,7 @@ export default function ChronologyScreen({ route, navigation }) {
ref = { bottomSheetModalLikelihoodRef }
index = { 1 }
snapPoints = { snapPoints }
backgroundStyle = { { backgroundColor : colorsheet } }
>
< BottomSheetScrollView contentContainerStyle = { styles . scrollView } >
{ dataSelectLikelihood . map ( item => renderLikelihood ( item ) ) }
@ -308,17 +357,14 @@ 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' ,