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