Skip to content

Commit 3a0b62d

Browse files
authored
Merge pull request #675 from codeforpdx/hotfix-contacts-and-messages
Hotfix contacts and messages
2 parents 9396c90 + 9cc603d commit 3a0b62d

File tree

10 files changed

+92
-62
lines changed

10 files changed

+92
-62
lines changed

package-lock.json

Lines changed: 54 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pass",
33
"homepage": ".",
4-
"version": "1.0.0-alpha",
4+
"version": "1.0.1-alpha",
55
"description": "",
66
"scripts": {
77
"start": "concurrently --kill-others \"npm run podserver\" \"npm run dev\"",

src/components/Contacts/ContactListTable.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ContactListTable = ({ contacts, deleteContact, handleDeleteContact, addCon
3333
const isSmallScreen = useMediaQuery(theme.breakpoints.down('sm'));
3434

3535
const [showAddContactModal, setShowAddContactModal] = useState(false);
36-
const [contactToEdit, setContactToEdit] = useState({});
36+
const [contactToEdit, setContactToEdit] = useState(null);
3737
const [isEditing, setIsEditing] = useState(false);
3838

3939
const handleSendMessage = (contactId) => {
@@ -89,6 +89,7 @@ const ContactListTable = ({ contacts, deleteContact, handleDeleteContact, addCon
8989
handleDeleteContact={handleDeleteContact}
9090
contactWebIds={contactWebIds}
9191
contacts={contacts}
92+
setContactToEdit={setContactToEdit}
9293
/>
9394
</Box>
9495
);

src/components/Contacts/ContactListTableDesktop.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const CustomToolbar = () => (
4040
* @param {Function} Props.editContact - Function to edit a contact
4141
* @param {Function} Props.handleSendMessage - Function to handle sending a message
4242
* @param {string} Props.'data-testid' - Test ID
43-
// * @param {Function} Props.handleProfileClick - Function to handle profile click
4443
* @returns {React.JSX.Element} The ContactListTableDesktop component
4544
*/
4645
const ContactListTableDesktop = ({

src/components/Modals/AddContactModal.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ const AddContactModal = ({
129129
useEffect(() => {
130130
// sets fields if form is set to Edit
131131
if (isEditing) {
132-
setUserGivenName(contactToEdit?.givenName);
133-
setUserFamilyName(contactToEdit?.familyName);
132+
setUserGivenName(contactToEdit?.givenName ?? '');
133+
setUserFamilyName(contactToEdit?.familyName ?? '');
134134

135135
// parse out webid and usernames and set them to the state values
136136
parsePodUrl();

src/components/Modals/NewMessageModal.jsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,19 @@ const NewMessageModal = ({ showModal, setShowModal, oldMessage = '', toField = '
5959
const isSmallScreen = useMediaQuery(theme.breakpoints.down('sm'));
6060

6161
const contactListOptions =
62-
data?.map((contact) => ({
63-
label: `${contact.person} ${contact.podUrl}`,
64-
id: contact.podUrl
65-
})) ?? [];
62+
data?.map((contact) => {
63+
let contactName;
64+
if (contact.givenName !== '' || contact.givenName !== null) {
65+
contactName = contact.givenName;
66+
}
67+
if (contact.familyName !== '' || contact.familyName !== null) {
68+
contactName += ` ${contact.familyName}`.trim();
69+
}
70+
return {
71+
label: `${contactName} ${contact.podUrl}`.trim(),
72+
id: contact.podUrl
73+
};
74+
}) ?? [];
6675
const recipientName = data?.filter((contact) => message.recipientPodUrl === contact.podUrl)[0];
6776
// Modifies message upon input
6877
const handleChange = (e) => {
@@ -137,7 +146,7 @@ const NewMessageModal = ({ showModal, setShowModal, oldMessage = '', toField = '
137146
data-testid="newMessageTo"
138147
id="recipientPodUrl"
139148
freeSolo
140-
value={recipientName?.person ?? message.recipientPodUrl}
149+
value={recipientName?.podUrl ?? message.recipientPodUrl}
141150
disablePortal
142151
autoSelect
143152
options={contactListOptions}

src/hooks/useContactsList.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,11 @@ const useContactsList = () => {
5050
};
5151

5252
const serialize = ({ givenName, familyName, webId }) => {
53-
let builder = buildThing(createThing({ name: encodeURIComponent(webId) }))
53+
const builder = buildThing(createThing({ name: encodeURIComponent(webId) }))
5454
.addUrl(RDF_PREDICATES.identifier, webId)
55-
.addUrl(RDF_PREDICATES.URL, webId.split('profile')[0]);
56-
57-
if (givenName) {
58-
builder = builder.addStringNoLocale(RDF_PREDICATES.givenName, givenName);
59-
}
60-
if (familyName) {
61-
builder = builder.addStringNoLocale(RDF_PREDICATES.familyName, familyName);
62-
}
55+
.addUrl(RDF_PREDICATES.URL, webId.split('profile')[0])
56+
.addStringNoLocale(RDF_PREDICATES.givenName, givenName ?? '')
57+
.addStringNoLocale(RDF_PREDICATES.familyName, familyName ?? '');
6358

6459
return builder.build();
6560
};

src/pages/Contacts.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// React Imports
2-
import React, { useState } from 'react';
2+
import React, { useEffect, useState } from 'react';
33
// Material UI Imports
44
import Box from '@mui/material/Box';
55
import Button from '@mui/material/Button';
@@ -42,12 +42,17 @@ const Contacts = () => {
4242
isLoading,
4343
isError,
4444
error,
45+
refetch,
4546
add: addContact,
4647
delete: deleteContact
4748
} = useContactsList();
4849
const { addNotification } = useNotification();
4950
const [fieldType, setFieldType] = useState('First Name');
5051

52+
useEffect(() => {
53+
refetch();
54+
}, []);
55+
5156
const getContactDisplayName = (contact) => {
5257
if (!contact) {
5358
return 'Unknown Contact';

test/components/Modals/NewMessageModal.test.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ it('selecting contact from autocomplete', async () => {
113113
{
114114
familyName: 'test',
115115
givenName: 'mock',
116-
person: 'mock test',
117116
podUrl: 'http://example/mocktest',
118117
thingId: 'http://example/mocktest/profile/card#me',
119118
webId: 'http://example/mocktest/profile/card#me'
@@ -135,5 +134,5 @@ it('selecting contact from autocomplete', async () => {
135134
// Enter to select dropdown option
136135
await userEvent.keyboard('[Enter]');
137136
// verify value of input field
138-
expect(toInput.value).toBe('mock test');
137+
expect(toInput.value).toBe('http://example/mocktest');
139138
});

0 commit comments

Comments
 (0)