import React, { useGlobal } from 'reactn' import { View, Text, Pressable } from 'react-native' import { capitalize } from 'lodash' import moment from 'moment' import { Motion } from '@legendapp/motion' import { validateDate } from 'react-native-minuit/src/actions/dateActions' import { Fonts, Palette, Style } from '../styles' import { projectsRef } from '../config/firebase' export default ({ actionList = [] }) => { const [currentProjectID] = useGlobal('currentProjectID') const onCheck = async ({ todoID, isChecked = false }) => { try { const updatedObject = { isChecked: !isChecked, completionTimestamp: !isChecked ? new Date() : null, } await projectsRef .doc(currentProjectID) .collection('todoList') .doc(todoID) .update(updatedObject) } catch (error) { console.log('error', error) } } if (!actionList.length) { return ( Vous n'avez pas d'actions en attente. ) } return actionList.map( ( { title = '', requestedCompletionTimestamp = null, isChecked = false, todoID = null }, index ) => { return ( onCheck({ todoID, isChecked })}> {isChecked && ( )} {capitalize(title)} {capitalize(moment(validateDate(requestedCompletionTimestamp)).fromNow())} {index !== actionList.length - 1 && ( )} ) } ) }