Skip to content

Commit 83ce7e8

Browse files
Merge pull request #707 from codeforpdx/691-qr-code-enhancement
Let's a user share their WebID via a QR code
2 parents ec9c174 + cdcbd42 commit 83ce7e8

File tree

4 files changed

+155
-20
lines changed

4 files changed

+155
-20
lines changed

package-lock.json

Lines changed: 32 additions & 0 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"react": "^18.2.0",
4747
"react-dom": "^18.2.0",
4848
"react-paginate": "^8.2.0",
49+
"react-qr-code": "^2.0.18",
4950
"react-router-dom": "^6.10.0",
5051
"react-router-hash-link": "^2.4.3",
5152
"react-webcam": "^7.2.0",
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import React, { useState } from 'react';
2+
import QRCode from 'react-qr-code';
3+
import QrCode2Icon from '@mui/icons-material/QrCode2';
4+
import {
5+
Dialog,
6+
DialogTitle,
7+
DialogContent,
8+
DialogActions,
9+
Button,
10+
Stack,
11+
Typography
12+
} from '@mui/material';
13+
14+
/**
15+
*
16+
* @memberof Profile
17+
* @name CreateQRCode
18+
* @param {object} Props - React props
19+
* @param {string} [Props.webId] - The webId of the user's profile
20+
* @returns {React.JSX.Element} The CreateQRCode Modal
21+
*/
22+
23+
const CreateQRCode = ({ webId }) => {
24+
const [qrIconClicked, setQrIconClicked] = useState(false);
25+
const [docUrl, setDocUrl] = useState(null);
26+
27+
const createQrCode = () => {
28+
setQrIconClicked(!qrIconClicked);
29+
const trimmedWebId = webId && webId.includes('#') ? webId.split('#')[0] : webId;
30+
setDocUrl(trimmedWebId);
31+
};
32+
33+
const closeModal = () => {
34+
setQrIconClicked(false);
35+
};
36+
37+
return (
38+
<>
39+
<Button
40+
variant="outlined"
41+
startIcon={<QrCode2Icon />}
42+
onClick={() => {
43+
createQrCode();
44+
}}
45+
>
46+
Show QR Code
47+
</Button>
48+
{qrIconClicked ? (
49+
<Dialog
50+
open={qrIconClicked}
51+
onClose={closeModal}
52+
aria-labelledby="qr-modal-title"
53+
maxWidth="xs"
54+
fullWidth
55+
>
56+
<DialogTitle id="qr-modal-title" sx={{ textAlign: 'center' }}>
57+
Share your WebID
58+
</DialogTitle>
59+
<DialogContent>
60+
<Stack spacing={2} alignItems="center" sx={{ py: 1 }}>
61+
<div style={{ background: '#fff' }}>
62+
<div style={{ width: 256 }}>
63+
<QRCode
64+
value={docUrl || ''}
65+
size={256}
66+
style={{ width: '100%', height: 'auto' }}
67+
viewBox="0 0 256 256"
68+
level="M"
69+
/>
70+
</div>
71+
</div>
72+
<Typography variant="body2" sx={{ wordBreak: 'break-all', textAlign: 'center' }}>
73+
{docUrl}
74+
</Typography>
75+
</Stack>
76+
</DialogContent>
77+
<DialogActions sx={{ justifyContent: 'center' }}>
78+
<Button
79+
onClick={closeModal}
80+
variant="contained"
81+
sx={{
82+
width: { xs: '90%', sm: '75%' }
83+
}}
84+
>
85+
Close
86+
</Button>
87+
</DialogActions>
88+
</Dialog>
89+
) : (
90+
''
91+
)}
92+
</>
93+
);
94+
};
95+
96+
export default CreateQRCode;

src/components/Profile/ProfileComponent.jsx

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { saveToClipboard } from '@utils';
1818
import ProfileInputField from './ProfileInputField';
1919
import ProfileEditButtonGroup from './ProfileEditButtonGroup';
2020
import ProfileImageField from './ProfileImageField';
21+
import CreateQRCode from './CreateQRCode';
2122

2223
/**
2324
* UserProfile - Component is a component that renders the user's profile on
@@ -148,26 +149,31 @@ const ProfileComponent = ({ contactProfile, webId }) => {
148149
/>
149150
</Box>
150151
{!contactProfile && (
151-
<Box sx={{ display: 'flex', flexDirection: 'row', gap: '10px', alignSelf: 'end' }}>
152-
<Typography sx={{ marginTop: '8px' }}>
153-
<Link to={`${signupLink}?webId=${encodeURIComponent(session.info.webId)}`}>
154-
Your Invite Link
155-
</Link>
156-
<IconButton
157-
aria-label="Copy Invite Link"
158-
edge="end"
159-
onClick={() => {
160-
saveToClipboard(
161-
`${signupLink}?webId=${encodeURIComponent(session.info.webId)}`,
162-
'Invite link copied to clipboard',
163-
addNotification
164-
);
165-
}}
166-
>
167-
<ContentCopyIcon />
168-
</IconButton>
169-
</Typography>
170-
</Box>
152+
<>
153+
<Box sx={{ display: 'flex', flexDirection: 'row', gap: '10px', alignSelf: 'end' }}>
154+
<Typography sx={{ marginTop: '8px' }}>
155+
<Link to={`${signupLink}?webId=${encodeURIComponent(session.info.webId)}`}>
156+
Your Invite Link
157+
</Link>
158+
<IconButton
159+
aria-label="Copy Invite Link"
160+
edge="end"
161+
onClick={() => {
162+
saveToClipboard(
163+
`${signupLink}?webId=${encodeURIComponent(session.info.webId)}`,
164+
'Invite link copied to clipboard',
165+
addNotification
166+
);
167+
}}
168+
>
169+
<ContentCopyIcon />
170+
</IconButton>
171+
</Typography>
172+
</Box>
173+
<Box sx={{ alignSelf: 'end' }}>
174+
<CreateQRCode webId={webId} />
175+
</Box>
176+
</>
171177
)}
172178
</form>
173179
</Box>

0 commit comments

Comments
 (0)