Skip to content

Commit 1cd061b

Browse files
committed
Hotfix: Include guards for .split
1 parent c92b0eb commit 1cd061b

File tree

13 files changed

+20
-21
lines changed

13 files changed

+20
-21
lines changed

src/components/CivicProfileForms/FormLayout.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import HMIS_FORM_LIST from './FormList';
2121
*/
2222
const FormLayout = ({ children }) => {
2323
const location = useLocation();
24-
const path = location.pathname.split('/').pop();
24+
const path = location.pathname?.split('/')?.pop() || '';
2525

2626
localStorage.setItem('restorePath', location.pathname);
2727
const pageIdx = HMIS_FORM_LIST.findIndex((form) => form.path === path);

src/components/Documents/DocumentCard.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import { truncateText, getTypeText } from '@utils';
4343
*/
4444
const DocumentCard = ({ document, onShare, onDelete, onPreview }) => {
4545
const location = useLocation();
46-
const profileWebId = decodeURIComponent(location.pathname.split('/')[2]);
46+
const profileWebId = decodeURIComponent(location.pathname?.split('/')?.[2] || '');
4747

4848
const [anchorEl, setAnchorEl] = useState(null);
4949
const [openMenu, setOpenMenu] = useState(null);

src/components/Modals/AddContactModal.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const AddContactModal = ({
8181
const isSmallScreen = useMediaQuery(theme.breakpoints.down('sm'));
8282
const [oidcProviders] = useState(() =>
8383
ENV.VITE_SUGGESTED_OIDC_OPTIONS !== undefined
84-
? [...ENV.VITE_SUGGESTED_OIDC_OPTIONS.split(', '), 'Other']
84+
? [...(ENV.VITE_SUGGESTED_OIDC_OPTIONS?.split(', ') || []), 'Other']
8585
: ['Other']
8686
);
8787
const [Oidc, setOIDC] = useState('');

src/components/Modals/NewMessageModal.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ const NewMessageModal = ({ showModal, setShowModal, oldMessage = '', toField = '
5151

5252
const [message, setMessage] = useState({
5353
recipientPodUrl:
54-
oldMessage && oldMessage.senderWebId ? oldMessage.senderWebId.split('profile')[0] : '',
54+
oldMessage && oldMessage.senderWebId
55+
? oldMessage.senderWebId?.split('profile')?.[0] || ''
56+
: '',
5557
title: oldMessage ? `RE:${oldMessage.title}`.replace('RE:RE:', 'RE:') : '',
5658
message: '',
5759
inReplyTo: oldMessage ? oldMessage.messageId : '',

src/components/Profile/CreateQRCode.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const CreateQRCode = ({ webId }) => {
2626

2727
const createQrCode = () => {
2828
setQrIconClicked(!qrIconClicked);
29-
const trimmedWebId = webId && webId.includes('#') ? webId.split('#')[0] : webId;
29+
const trimmedWebId = webId && webId.includes('#') ? webId?.split('#')?.[0] || webId : webId;
3030
setDocUrl(trimmedWebId);
3131
};
3232

src/components/Signup/podSignupHelpers/initializePod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const initializePod = async (
6868
let contactsList = createSolidDataset();
6969
let builder = buildThing(createThing({ name: encodeURIComponent(caseManagerWebId) }))
7070
.addUrl(RDF_PREDICATES.identifier, caseManagerWebId)
71-
.addUrl(RDF_PREDICATES.URL, caseManagerWebId.split('profile')[0]);
71+
.addUrl(RDF_PREDICATES.URL, caseManagerWebId?.split('profile')?.[0] || '');
7272

7373
if (caseManagerFirstName) {
7474
builder = builder.addStringNoLocale(RDF_PREDICATES.givenName, caseManagerFirstName);

src/contexts/SignedInUserContext.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const SignedInUserContextProvider = ({ children }) => {
5656
const loadUserInfo = async () => {
5757
try {
5858
let fetchedPodUrl = (await getPodUrlAll(webId, { fetch: session.fetch }))[0];
59-
fetchedPodUrl = fetchedPodUrl || webId.split('profile')[0];
59+
fetchedPodUrl = fetchedPodUrl || webId?.split('profile')?.[0] || '';
6060
setPodUrl(fetchedPodUrl);
6161
const fetchedProfileData = await fetchProfileInfo(webId);
6262
if (fetchedProfileData.profileInfo.profileImage) {

src/layouts/Breadcrumbs.jsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,14 @@ import Typography from '@mui/material/Typography';
1717
const Breadcrumbs = () => {
1818
const location = useLocation();
1919

20-
const crumbs = location?.pathname
21-
.split('/')
22-
.slice(1)
23-
.map((crumb) => {
20+
const crumbs =
21+
location?.pathname?.split('/') ||
22+
[].slice(1).map((crumb) => {
2423
let string = crumb;
2524
string = decodeURIComponent(crumb.replace('-', ' '));
2625
if (!string.includes('http')) {
27-
string = string
28-
.split(' ')
29-
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
30-
.join(' ');
26+
string =
27+
string?.split(' ') || [].map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(' ');
3128
}
3229
return string;
3330
});

src/model-helpers/Profile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const updateProfileInfo = async (session, profileData, inputValues) => {
103103
export const uploadProfileImage = async (session, profileData, inputImage) => {
104104
let { profileDataset, profileThing } = profileData;
105105

106-
const profileContainer = `${session.info.webId.split('card')[0]}`;
106+
const profileContainer = `${session.info.webId?.split('card')?.[0] || ''}`;
107107
const profileImgFilename = inputImage.name.replace(' ', '%20');
108108

109109
const savedFile = await saveFileInContainer(profileContainer, inputImage, {

src/pages/CivicProfile.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const CivicProfile = () => {
2020
const location = useLocation();
2121

2222
localStorage.setItem('restorePath', location.pathname);
23-
const currentForm = location.pathname.split('/').pop();
23+
const currentForm = location.pathname?.split('/')?.pop() || '';
2424

2525
return (
2626
<Container>

0 commit comments

Comments
 (0)