From 88c6e1b0911f9a3d90909941413aaf68ae0c385a Mon Sep 17 00:00:00 2001 From: AlexisG Date: Mon, 28 Oct 2024 16:31:05 +0100 Subject: [PATCH 1/7] feat: Change wording of group manage button f --- src/components/GroupsSelect/GroupsSelect.spec.jsx | 8 ++++---- src/locales/de.json | 2 +- src/locales/en.json | 2 +- src/locales/es.json | 2 +- src/locales/fr.json | 2 +- src/locales/nl_NL.json | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/components/GroupsSelect/GroupsSelect.spec.jsx b/src/components/GroupsSelect/GroupsSelect.spec.jsx index 394fca773..68126167b 100644 --- a/src/components/GroupsSelect/GroupsSelect.spec.jsx +++ b/src/components/GroupsSelect/GroupsSelect.spec.jsx @@ -34,7 +34,7 @@ describe('GroupsSelect', () => { setup() act(() => { - fireEvent.click(screen.getByText('Manage groups')) + fireEvent.click(screen.getByText('Groups')) }) for (const group of groups) { @@ -47,7 +47,7 @@ describe('GroupsSelect', () => { setup() act(() => { - fireEvent.click(screen.getByText('Manage groups')) + fireEvent.click(screen.getByText('Groups')) }) act(() => { @@ -98,7 +98,7 @@ describe('GroupsSelect', () => { setup() act(() => { - fireEvent.click(screen.getByText('Manage groups')) + fireEvent.click(screen.getByText('Groups')) }) act(() => { @@ -150,7 +150,7 @@ describe('GroupsSelect', () => { act(() => { // it should replace the field by input with group name as value - fireEvent.click(screen.getByText('Manage groups')) + fireEvent.click(screen.getByText('Groups')) }) act(() => { diff --git a/src/locales/de.json b/src/locales/de.json index 439500caa..53a830171 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -107,7 +107,7 @@ }, "groups": { "none": "Es existiert keine Gruppe.", - "manage": "Verwalte Gruppen", + "manage": "Gruppen", "create": "Erstelle eine Gruppe", "created": { "success": "Die Gruppe wurde erfolgreich erstellt.", diff --git a/src/locales/en.json b/src/locales/en.json index 926b09947..8dc2b0f9b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -143,7 +143,7 @@ }, "groups": { "none": "There is no existing group.", - "manage": "Manage groups", + "manage": "Groups", "create": "Create a group", "created": { "success": "The group has been created correctly.", diff --git a/src/locales/es.json b/src/locales/es.json index cc83e8f56..495df1520 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -126,7 +126,7 @@ }, "groups": { "none": "No existe un grupo.", - "manage": "Administrar grupos", + "manage": "Grupos", "create": "Crear un grupo", "created": { "success": "El grupo ha sido creado correctamente.", diff --git a/src/locales/fr.json b/src/locales/fr.json index eba3af0ef..e8f7bb54a 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -143,7 +143,7 @@ }, "groups": { "none": "Il n'y a pas encore de groupes.", - "manage": "Gérer les groupes", + "manage": "Groupes", "create": "Créer un groupe", "created": { "success": "Le groupe a bien été créé.", diff --git a/src/locales/nl_NL.json b/src/locales/nl_NL.json index ee7ca17f3..fe6e75a06 100644 --- a/src/locales/nl_NL.json +++ b/src/locales/nl_NL.json @@ -107,7 +107,7 @@ }, "groups": { "none": "Er is nog geen groep.", - "manage": "Groepen beheren", + "manage": "Groepen", "create": "Groep samenstellen", "created": { "success": "De groep is samengesteld.", From c11f8c63ef77808d051cc15ef7b5225d3bf33997 Mon Sep 17 00:00:00 2001 From: AlexisG Date: Mon, 28 Oct 2024 16:35:51 +0100 Subject: [PATCH 2/7] refactor: Remove create and update Contact helpers These helpers simply wraps around an existing methods. --- src/components/Intents/CreateContact.jsx | 4 ++-- src/components/Modals/ContactFormModal.spec.jsx | 2 -- src/connections/allContacts.js | 7 +------ 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/components/Intents/CreateContact.jsx b/src/components/Intents/CreateContact.jsx index f316d234f..f5fd68b21 100644 --- a/src/components/Intents/CreateContact.jsx +++ b/src/components/Intents/CreateContact.jsx @@ -1,13 +1,13 @@ import flow from 'lodash/flow' import PropTypes from 'prop-types' import React from 'react' +import { DOCTYPE_CONTACTS } from 'src/helpers/doctypes' import { withClient } from 'cozy-client' import IntentHeader from 'cozy-ui/transpiled/react/IntentHeader' import { translate } from 'cozy-ui/transpiled/react/providers/I18n' import IntentMain from './IntentMain' -import { createContact as createContactWithClient } from '../../connections/allContacts' import ContactForm from '../ContactCard/ContactForm' const CreateContact = ({ client, data, onTerminate, onError, onCancel }) => { @@ -15,7 +15,7 @@ const CreateContact = ({ client, data, onTerminate, onError, onCancel }) => { try { const me = !!data.me if (me) contact.metadata.me = true - const resp = await createContactWithClient(client, contact) + const resp = await client.create(DOCTYPE_CONTACTS, contact) onTerminate(resp.data) } catch (e) { onError('Could not create contact') diff --git a/src/components/Modals/ContactFormModal.spec.jsx b/src/components/Modals/ContactFormModal.spec.jsx index 42d7f0f33..6338613c3 100644 --- a/src/components/Modals/ContactFormModal.spec.jsx +++ b/src/components/Modals/ContactFormModal.spec.jsx @@ -9,8 +9,6 @@ import { createOrUpdateContact } from '../../connections/allContacts' import AppLike from '../../tests/Applike' jest.mock('../../connections/allContacts', () => ({ - createContact: jest.fn().mockResolvedValue({ data: 'created' }), - updateContact: jest.fn().mockResolvedValue({ data: 'updated' }), createOrUpdateContact: jest.fn() })) jest.mock('cozy-client/dist/hooks', () => ({ diff --git a/src/connections/allContacts.js b/src/connections/allContacts.js index 11b2285f6..cc02cabf1 100644 --- a/src/connections/allContacts.js +++ b/src/connections/allContacts.js @@ -38,11 +38,6 @@ export const importContact = async (client, attributes) => { return client.create(DOCTYPE_CONTACTS, attributes, null) } -export const createContact = (client, attributes) => - client.create(DOCTYPE_CONTACTS, attributes) - -export const updateContact = (client, contact) => client.save(contact) - const isContactSynced = contact => { return Object.keys(contact.cozyMetadata?.sync || {}).length > 0 } @@ -88,7 +83,7 @@ export const createOrUpdateContact = async ({ formData, selectedGroup }) => { - const createOrUpdate = isUpdated ? updateContact : createContact + const createOrUpdate = isUpdated ? client.save : client.create let updatedContact = merge({}, formData) if (hasSelectedGroup(selectedGroup)) { From e88c347480d57f64bf8e5382ebc510fe850a061e Mon Sep 17 00:00:00 2001 From: AlexisG Date: Mon, 28 Oct 2024 16:37:15 +0100 Subject: [PATCH 3/7] feat: Add favorite button --- src/components/Modals/ContactInfoTitle.jsx | 35 +++++++++++++++++++++- src/connections/allContacts.js | 11 +++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/components/Modals/ContactInfoTitle.jsx b/src/components/Modals/ContactInfoTitle.jsx index 10ab1128d..5a5f15c83 100644 --- a/src/components/Modals/ContactInfoTitle.jsx +++ b/src/components/Modals/ContactInfoTitle.jsx @@ -1,17 +1,22 @@ import get from 'lodash/get' +import throttle from 'lodash/throttle' import PropTypes from 'prop-types' -import React from 'react' +import React, { useCallback } from 'react' import { useNavigate } from 'react-router-dom' +import { useClient } from 'cozy-client' import minilog from 'cozy-minilog' import Button from 'cozy-ui/transpiled/react/Buttons' import Grid from 'cozy-ui/transpiled/react/Grid' import Icon from 'cozy-ui/transpiled/react/Icon' import RenameIcon from 'cozy-ui/transpiled/react/Icons/Rename' +import StarIcon from 'cozy-ui/transpiled/react/Icons/Star' +import StarOutlineIcon from 'cozy-ui/transpiled/react/Icons/StarOutline' import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash' import { useAlert } from 'cozy-ui/transpiled/react/providers/Alert' import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' +import { updateContact } from '../../connections/allContacts' import { updateContactGroups } from '../../helpers/groups' import ContactIdentity from '../ContactCard/ContactIdentity' import { fullContactPropTypes } from '../ContactPropTypes' @@ -39,6 +44,7 @@ const ContactInfoTitle = ({ contact, allGroups }) => { const navigate = useNavigate() const { t } = useI18n() const { showAlert } = useAlert() + const client = useClient() const handleChange = async nextGroups => { try { @@ -53,6 +59,23 @@ const ContactInfoTitle = ({ contact, allGroups }) => { await contact.groups.addById(createdGroup._id) } + // eslint-disable-next-line react-hooks/exhaustive-deps + const throttledUpdateContact = useCallback(throttle(updateContact, 500), []) + + const handleFavorite = () => { + throttledUpdateContact({ + client, + contact, + attributes: { + cozyMetadata: { + favorite: !contact.cozyMetadata?.favorite + } + } + }) + } + const isFavorite = contact.cozyMetadata?.favorite ?? false + const favoriteIcon = isFavorite ? StarIcon : StarOutlineIcon + const handleValue = get(contact, 'relationships.groups.data', []) return ( @@ -74,6 +97,16 @@ const ContactInfoTitle = ({ contact, allGroups }) => { menuPosition="fixed" /> + +