From e5a7f78290ed340650dd088d9a0efd537919616e Mon Sep 17 00:00:00 2001 From: JF-Cozy Date: Tue, 17 Oct 2023 10:40:24 +0200 Subject: [PATCH] fix: Trip title wasn't showing correct wording see https://github.com/cozy/cozy-client/issues/1403 --- .../ContactToPlaceDialogActions.jsx | 2 +- src/components/ContactToPlace/helpers.js | 57 +++++++++++++------ 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/components/ContactToPlace/ContactToPlaceDialogActions.jsx b/src/components/ContactToPlace/ContactToPlaceDialogActions.jsx index 2307ac1a..49189139 100644 --- a/src/components/ContactToPlace/ContactToPlaceDialogActions.jsx +++ b/src/components/ContactToPlace/ContactToPlaceDialogActions.jsx @@ -53,7 +53,7 @@ const ContactToPlaceDialogActions = () => { const handleDelete = async () => { showAlert(t('contactToPlace.removeSuccess'), 'success') onClose() - await removeRelationship({ client, timeserie, type, contact }) + await removeRelationship({ client, timeserie, type, t, contact }) } return ( diff --git a/src/components/ContactToPlace/helpers.js b/src/components/ContactToPlace/helpers.js index b69ae729..4ed721d6 100644 --- a/src/components/ContactToPlace/helpers.js +++ b/src/components/ContactToPlace/helpers.js @@ -92,6 +92,7 @@ export const removeRelationship = async ({ client, timeserie, type, + t, contact }) => { const { address } = getContactAddressAndIndexFromRelationships({ @@ -104,17 +105,29 @@ export const removeRelationship = async ({ await client.save(contact) - const { data: newTimeserie } = await getRelationshipByType( - timeserie, - type - ).remove() + const { data: timeserieWithUpdatedRelationships } = + await getRelationshipByType(timeserie, type).remove() unset( - newTimeserie, + timeserieWithUpdatedRelationships, `relationships.${getRelationshipKey(type)}.data.metadata.addressId` ) - await client.save(newTimeserie) + set( + timeserieWithUpdatedRelationships, + 'aggregation.automaticTitle', + makeAggregationTitle( + { + ...timeserieWithUpdatedRelationships, + // relationships are not included, we need to add them manually + startPlaceContact: timeserie.startPlaceContact, + endPlaceContact: timeserie.endPlaceContact + }, + t + ) + ) + + await client.save(timeserieWithUpdatedRelationships) } export const addAddressToContact = ({ @@ -164,22 +177,32 @@ const createRelationship = async ({ const { data: newContact } = await client.save(contactToSave) - const { data: newTimeserie } = await getRelationshipByType( - timeserie, - type - ).add(newContact) + const { data: timeserieWithUpdatedRelationships } = + await getRelationshipByType(timeserie, type).add(newContact) set( - newTimeserie, - 'aggregation.automaticTitle', - makeAggregationTitle(newTimeserie, t) + timeserieWithUpdatedRelationships, + `relationships.${getRelationshipKey(type)}.data.metadata`, + { + addressId + } ) - set(newTimeserie, `relationships.${getRelationshipKey(type)}.data.metadata`, { - addressId - }) + set( + timeserieWithUpdatedRelationships, + 'aggregation.automaticTitle', + makeAggregationTitle( + { + ...timeserieWithUpdatedRelationships, + // relationships are not included, we need to add them manually + startPlaceContact: timeserie.startPlaceContact, + endPlaceContact: timeserie.endPlaceContact + }, + t + ) + ) - await client.save(newTimeserie) + await client.save(timeserieWithUpdatedRelationships) } const updateRelationship = async ({