Skip to content

Commit

Permalink
Merge branch 'develop' into fix/367-loading-state-for-submit-buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-y-ito committed Mar 29, 2024
2 parents 656fa55 + 41c6813 commit 9fcb5e9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
Binary file added public/images/og.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed public/images/og.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const metadata: Metadata = {
url: APP_CONST.BASE_URL,
images: [
{
url: `${APP_CONST.BASE_URL}/images/og.png?v=0`,
url: `${APP_CONST.BASE_URL}/images/og.jpg?v=0`,
width: 1200,
height: 630,
alt: APP_CONST.NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,43 @@ export const InviteMemberDialogContent = ({
groupId,
}: IInviteMemberDialogContentProps) => {
const [isLinkButtonClicked, setIsLinkButtonClicked] = useState(false);
const [hash, setHash] = useState('');

/**
* This useEffect has two dependencies. When one of them,`isDialogOpen` state, is changed to true, the setup is fired
* which is generating the invitation link hash and put it as state `hash`
*/
useEffect(() => {
const getHash = async () => {
if (!isDialogOpen) return;

const result = await putGenerateInvitationLinkHash(groupId);
if (!result.ok) {
alert('Something went wrong. Please try again');
return;
}
setHash(result.value.invitationLinkHash);
};

getHash();
}, [isDialogOpen, groupId]);
/**
* Handle the link copy button click.
* If the generatedLink is not valid, do nothing.
* If success, generated invitation link URL is copied to clipboard and change the text of button to 'Copied!'
* *A hash, which is part of the URL, is already generated when the dialog open
*/
const handleLinkCopy = async () => {
setIsLinkButtonClicked(true);
const result = await putGenerateInvitationLinkHash(groupId);

if (!result.ok) {
alert('Something went wrong. Please try again');
return;
try {
if (!hash) throw new Error('Invitation link hash is not set.');
return await navigator.clipboard.writeText(`${CLIENT_BASE_URL}/groups/join/${hash}`);
} catch (err) {
console.error(
'Error occurred while copying the link:',
err instanceof Error ? err.message : err,
);
alert('Error occurred while copying the link. Please try again.');
}

const hash = result.value.invitationLinkHash;
navigator.clipboard.writeText(`${CLIENT_BASE_URL}/groups/join/${hash}`);
return;
};

Expand Down

0 comments on commit 9fcb5e9

Please sign in to comment.