Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { PERMISSIONS } from "@hey/data/constants";
2import type { GroupFragment } from "@hey/indexer";
3import stopEventPropagation from "@/helpers/stopEventPropagation";
4import { useAccountStore } from "@/store/persisted/useAccountStore";
5import CancelGroupMembershipRequest from "./CancelGroupMembershipRequest";
6import JoinWithRulesCheck from "./JoinWithRulesCheck";
7import Leave from "./Leave";
8
9interface JoinLeaveButtonProps {
10 hideJoinButton?: boolean;
11 hideLeaveButton?: boolean;
12 group: GroupFragment;
13 small?: boolean;
14}
15
16const JoinLeaveButton = ({
17 hideJoinButton = false,
18 hideLeaveButton = false,
19 group,
20 small = false
21}: JoinLeaveButtonProps) => {
22 const { currentAccount } = useAccountStore();
23
24 if (currentAccount?.address === group.owner) {
25 return null;
26 }
27
28 // Hide join/leave button for all permission groups
29 if (Object.values(PERMISSIONS).includes(group.address)) {
30 return null;
31 }
32
33 return (
34 <div className="contents" onClick={stopEventPropagation}>
35 {!hideJoinButton &&
36 (group.operations?.isMember ||
37 group.operations?.hasRequestedMembership ? null : (
38 <JoinWithRulesCheck group={group} small={small} />
39 ))}
40 {!hideLeaveButton &&
41 (group.operations?.isMember ? (
42 <Leave group={group} small={small} />
43 ) : group.operations?.hasRequestedMembership ? (
44 <CancelGroupMembershipRequest group={group} small={small} />
45 ) : null)}
46 </div>
47 );
48};
49
50export default JoinLeaveButton;