Skip to content

Commit

Permalink
Merge pull request #91 from JustaName-id/anthonyk/engr-738-jan-sdk-in…
Browse files Browse the repository at this point in the history
…vitations

feat(widget): implemented invitations feature
  • Loading branch information
HadiKhai authored Jan 16, 2025
2 parents 08bfb8c + 989de8c commit 0d06bf7
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Records, useAcceptSubname, useEnsAvatar, useRejectSubname } from '@justaname.id/react';
import {
Avatar,
Button,
ClickableItem,
Flex
} from '@justweb3/ui';
import React from 'react';

export interface SubnameInvitationItemProps {
subname: Records;
onInvitationChange: () => void;
}

export const SubnameInvitationItem: React.FC<SubnameInvitationItemProps> = ({
subname,
onInvitationChange,
}) => {
const { acceptSubname, isAcceptSubnamePending } = useAcceptSubname();
const { rejectSubname, isRejectSubnamePending } = useRejectSubname();
const { avatar } = useEnsAvatar({
ens: subname.ens,
});
return (
<ClickableItem
title={subname.ens}
style={{
width: '100%',
}}
left={<Avatar src={avatar} initial={subname.ens[0]} />}
right={
<Flex direction='row' gap='10px' align='center'>
<Button
type="button"
variant="primary"
onClick={() => acceptSubname({
ens: subname.ens,
}).then(onInvitationChange)}
style={{ flexGrow: '0.5' }}
disabled={isAcceptSubnamePending || isRejectSubnamePending}
>
Accept
</Button>
<Button
type="button"
variant="secondary"
onClick={() => rejectSubname({
ens: subname.ens,
}).then(onInvitationChange)}
style={{ flexGrow: '0.5' }}
disabled={isAcceptSubnamePending || isRejectSubnamePending}
>
Decline
</Button>
</Flex>
}
loading={isAcceptSubnamePending || isRejectSubnamePending}
/>
);
};
1 change: 1 addition & 0 deletions packages/@justweb3/widget/src/lib/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './SelectSubnameItem';
export * from './SubnameInvitationItem';
export * from './Loading';
export * from './JustaNameFooter';
export * from './UpdateRecordItem';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

.contentWrapper {
max-height: 50vh;
max-height: 40vh;
overflow-y: auto;
overflow-x: hidden;
}
Expand Down
19 changes: 17 additions & 2 deletions packages/@justweb3/widget/src/lib/dialogs/SignInDialog/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Records,
useAccountEnsNames,
useAccountInvitations,
useAccountSubnames,
useAddSubname,
useEnsSignIn,
Expand All @@ -26,6 +27,7 @@ import {
import clsx from 'clsx';
import React, { FC, Fragment, useMemo, useState } from 'react';
import { SelectSubnameItem } from '../../components/SelectSubnameItem';
import { SubnameInvitationItem } from '../../components/SubnameInvitationItem';
import { useDebounce } from '../../hooks/useDebounce';
import { DefaultDialog } from '../DefaultDialog';
import styles from './SignInDialog.module.css';
Expand Down Expand Up @@ -81,6 +83,10 @@ export const SignInDialog: FC<SignInDialogProps> = ({
const { isConnected, address } = useMountedAccount();
const { accountSubnames, isAccountSubnamesPending } = useAccountSubnames();
const { accountEnsNames, isAccountEnsNamesPending } = useAccountEnsNames();
const { invitations, isInvitationsPending, refetchInvitations } = useAccountInvitations({
chainId,
enabled: !!chainId && !!address,
});

const { primaryName, isPrimaryNameLoading, refetchPrimaryName } = usePrimaryName({
address,
Expand Down Expand Up @@ -286,24 +292,33 @@ export const SignInDialog: FC<SignInDialogProps> = ({
</SPAN>
</Badge>
{isAccountSubnamesPending ||
isInvitationsPending ||
isAccountEnsNamesPending ||
isOffchainResolversPending ? (
<div className={styles.loadingContainer}>
<LoadingSpinner color={'var(--justweb3-primary-color)'} />
</div>
) : (
<Flex direction="column" gap="20px">
<Flex direction="column" gap="10px">
<TransitionElement
visible={shouldBeAbleToSelect}
maxheight="fit-content"
>
<Flex direction="column" gap="20px" justify={'space-between'}>
<Flex direction="column" gap="10px" justify={'space-between'}>
<H2>Select an ENS</H2>
<Flex
direction="column"
gap="15px"
className={clsx(styles.contentWrapper)}
>
{invitations.length > 0 && invitations.map((inv, index) => (
<Fragment key={'subname-invitation-' + index}>
<SubnameInvitationItem
subname={inv}
onInvitationChange={refetchInvitations}
/>
</Fragment>
))}
{!isPrimaryNameLoading && primarySubname &&
<SelectSubnameItem
selectedSubname={subnameSigningIn}
Expand Down

0 comments on commit 0d06bf7

Please sign in to comment.