import { getDtendProperty } from 'proton-shared/lib/calendar/vcalConverter' ; import { omit } from 'proton-shared/lib/helpers/object' ; import { VcalVeventComponent } from 'proton-shared/lib/interfaces/calendar/VcalModel' ; import { getSafeRruleUntil } from './helper' ; import { getStartDateTimeMerged , getEndDateTimeMerged } from './getDateTimeMerged' ; import { UpdateAllPossibilities } from '../eventActions/getRecurringUpdateAllPossibilities' ; const getComponentWithUpdatedRrule = ( component ) => { const { rrule } = component ; if ( ! rrule ) { return omit ( component , [ 'rrule' ] ) ; } if ( rrule . value . until ) { return { ... component , rrule : getSafeRruleUntil ( rrule , component ) , } ; } return { ... component , rrule , } ; } ; interface Arguments { component : VcalVeventComponent ; originalComponent : VcalVeventComponent ; mode : UpdateAllPossibilities ; isSingleEdit : boolean ; isInvitation : boolean ; } const updateAllRecurrence = ( { component , originalComponent , mode , isInvitation } ) : VcalVeventComponent => { const veventWithOldUID = { ... component , uid : { value : originalComponent . uid . value } , } as VcalVeventComponent ; delete veventWithOldUID [ 'recurrence-id' ] ; if ( mode === UpdateAllPossibilities . KEEP_SINGLE_EDITS || isInvitation ) { if ( originalComponent . exdate ) { veventWithOldUID . exdate = originalComponent . exdate ; } veventWithOldUID . dtstart = originalComponent . dtstart ; veventWithOldUID . dtend = getEndDateTimeMerged ( component . dtstart , getDtendProperty ( component ) , veventWithOldUID . dtstart ) ; return veventWithOldUID ; } if ( mode === UpdateAllPossibilities . KEEP_ORIGINAL_START_DATE_BUT_USE_TIME ) { delete veventWithOldUID . exdate ; const mergedDtstart = getStartDateTimeMerged ( component . dtstart , originalComponent . dtstart ) ; const mergedDtend = getEndDateTimeMerged ( component . dtstart , getDtendProperty ( component ) , mergedDtstart ) ; veventWithOldUID . dtstart = mergedDtstart ; veventWithOldUID . dtend = mergedDtend ; return veventWithOldUID ; } delete veventWithOldUID . exdate ; return getComponentWithUpdatedRrule ( veventWithOldUID ) ; } ; export default updateAllRecurrence ;