Skip to content

Commit

Permalink
fix: Trip title wasn't showing correct wording
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Oct 17, 2023
1 parent 213e191 commit e5a7f78
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
57 changes: 40 additions & 17 deletions src/components/ContactToPlace/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const removeRelationship = async ({
client,
timeserie,
type,
t,
contact
}) => {
const { address } = getContactAddressAndIndexFromRelationships({
Expand All @@ -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 = ({
Expand Down Expand Up @@ -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 ({
Expand Down

0 comments on commit e5a7f78

Please sign in to comment.