Skip to content

Commit

Permalink
Refactor dev tool
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine committed Jan 10, 2025
1 parent 133dd22 commit d7031bd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
19 changes: 12 additions & 7 deletions apps/xmtp.chat/src/components/ManageConversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const ManageConversation: React.FC = () => {
const [addedMembers, setAddedMembers] = useState<string[]>([]);
const [removedMembers, setRemovedMembers] = useState<SafeGroupMember[]>([]);
const [permissionsPolicy, setPermissionsPolicy] =
useState<GroupPermissionsOptions>(GroupPermissionsOptions.AllMembers);
useState<GroupPermissionsOptions>(GroupPermissionsOptions.Default);
const [policySet, setPolicySet] = useState<PolicySet>({
addAdminPolicy: PermissionPolicy.Admin,
addMemberPolicy: PermissionPolicy.Admin,
Expand All @@ -63,6 +63,7 @@ export const ManageConversation: React.FC = () => {
updateGroupImageUrlSquarePolicy: PermissionPolicy.Allow,
updateGroupNamePolicy: PermissionPolicy.Allow,
updateGroupPinnedFrameUrlPolicy: PermissionPolicy.Allow,
updateMessageExpirationPolicy: PermissionPolicy.Allow,
});
const [updateConversationError, setUpdateConversationError] = useState<
string | null
Expand All @@ -76,7 +77,7 @@ export const ManageConversation: React.FC = () => {
const [pinnedFrameUrl, setPinnedFrameUrl] = useState("");

const policyTooltip = useMemo(() => {
if (permissionsPolicy === GroupPermissionsOptions.AllMembers) {
if (permissionsPolicy === GroupPermissionsOptions.Default) {
return "All members of the group can perform group actions";
} else if (permissionsPolicy === GroupPermissionsOptions.AdminOnly) {
return "Only admins can perform group actions";
Expand All @@ -86,7 +87,7 @@ export const ManageConversation: React.FC = () => {

useEffect(() => {
if (
permissionsPolicy === GroupPermissionsOptions.AllMembers ||
permissionsPolicy === GroupPermissionsOptions.Default ||
permissionsPolicy === GroupPermissionsOptions.CustomPolicy
) {
setPolicySet({
Expand All @@ -98,6 +99,7 @@ export const ManageConversation: React.FC = () => {
updateGroupImageUrlSquarePolicy: PermissionPolicy.Allow,
updateGroupNamePolicy: PermissionPolicy.Allow,
updateGroupPinnedFrameUrlPolicy: PermissionPolicy.Allow,
updateMessageExpirationPolicy: PermissionPolicy.Admin,
});
} else {
setPolicySet({
Expand All @@ -109,6 +111,7 @@ export const ManageConversation: React.FC = () => {
updateGroupImageUrlSquarePolicy: PermissionPolicy.Admin,
updateGroupNamePolicy: PermissionPolicy.Admin,
updateGroupPinnedFrameUrlPolicy: PermissionPolicy.Admin,
updateMessageExpirationPolicy: PermissionPolicy.Admin,
});
}
}, [permissionsPolicy]);
Expand Down Expand Up @@ -161,7 +164,7 @@ export const ManageConversation: React.FC = () => {
permissionsPolicy !== GroupPermissionsOptions.CustomPolicy
) {
switch (permissionsPolicy) {
case GroupPermissionsOptions.AllMembers: {
case GroupPermissionsOptions.Default: {
await conversation?.updatePermission(
PermissionUpdateType.AddMember,
PermissionPolicy.Deny,
Expand Down Expand Up @@ -312,8 +315,8 @@ export const ManageConversation: React.FC = () => {
const permissions = await conversation.permissions();
const policyType = permissions.policyType;
switch (policyType) {
case GroupPermissionsOptions.AllMembers:
setPermissionsPolicy(GroupPermissionsOptions.AllMembers);
case GroupPermissionsOptions.Default:
setPermissionsPolicy(GroupPermissionsOptions.Default);
setPolicySet({
addAdminPolicy: PermissionPolicy.Admin,
addMemberPolicy: PermissionPolicy.Admin,
Expand All @@ -323,6 +326,7 @@ export const ManageConversation: React.FC = () => {
updateGroupImageUrlSquarePolicy: PermissionPolicy.Allow,
updateGroupNamePolicy: PermissionPolicy.Allow,
updateGroupPinnedFrameUrlPolicy: PermissionPolicy.Allow,
updateMessageExpirationPolicy: PermissionPolicy.Admin,
});
break;
case GroupPermissionsOptions.AdminOnly:
Expand All @@ -336,6 +340,7 @@ export const ManageConversation: React.FC = () => {
updateGroupImageUrlSquarePolicy: PermissionPolicy.Admin,
updateGroupNamePolicy: PermissionPolicy.Admin,
updateGroupPinnedFrameUrlPolicy: PermissionPolicy.Admin,
updateMessageExpirationPolicy: PermissionPolicy.Admin,
});
break;
case GroupPermissionsOptions.CustomPolicy:
Expand Down Expand Up @@ -486,7 +491,7 @@ export const ManageConversation: React.FC = () => {
);
}}
data={[
{ value: "0", label: "All members" },
{ value: "0", label: "Default" },
{ value: "1", label: "Admins only" },
{ value: "2", label: "Custom policy" },
]}
Expand Down
11 changes: 7 additions & 4 deletions apps/xmtp.chat/src/components/NewConversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const NewConversation: React.FC = () => {
const [members, setMembers] = useState<string[]>([]);
const [isDmGroup, setIsDmGroup] = useState(false);
const [permissionsPolicy, setPermissionsPolicy] =
useState<GroupPermissionsOptions>(GroupPermissionsOptions.AllMembers);
useState<GroupPermissionsOptions>(GroupPermissionsOptions.Default);
const [policySet, setPolicySet] = useState<PolicySet>({
addAdminPolicy: PermissionPolicy.Admin,
addMemberPolicy: PermissionPolicy.Admin,
Expand All @@ -53,6 +53,7 @@ export const NewConversation: React.FC = () => {
updateGroupImageUrlSquarePolicy: PermissionPolicy.Allow,
updateGroupNamePolicy: PermissionPolicy.Allow,
updateGroupPinnedFrameUrlPolicy: PermissionPolicy.Allow,
updateMessageExpirationPolicy: PermissionPolicy.Allow,
});
const [createConversationError, setCreateConversationError] = useState<
string | null
Expand All @@ -64,7 +65,7 @@ export const NewConversation: React.FC = () => {
const [pinnedFrameUrl, setPinnedFrameUrl] = useState("");

const policyTooltip = useMemo(() => {
if (permissionsPolicy === GroupPermissionsOptions.AllMembers) {
if (permissionsPolicy === GroupPermissionsOptions.Default) {
return "All members of the group can perform group actions";
} else if (permissionsPolicy === GroupPermissionsOptions.AdminOnly) {
return "Only admins can perform group actions";
Expand All @@ -74,7 +75,7 @@ export const NewConversation: React.FC = () => {

useEffect(() => {
if (
permissionsPolicy === GroupPermissionsOptions.AllMembers ||
permissionsPolicy === GroupPermissionsOptions.Default ||
permissionsPolicy === GroupPermissionsOptions.CustomPolicy
) {
setPolicySet({
Expand All @@ -86,6 +87,7 @@ export const NewConversation: React.FC = () => {
updateGroupImageUrlSquarePolicy: PermissionPolicy.Allow,
updateGroupNamePolicy: PermissionPolicy.Allow,
updateGroupPinnedFrameUrlPolicy: PermissionPolicy.Allow,
updateMessageExpirationPolicy: PermissionPolicy.Admin,
});
} else {
setPolicySet({
Expand All @@ -97,6 +99,7 @@ export const NewConversation: React.FC = () => {
updateGroupImageUrlSquarePolicy: PermissionPolicy.Admin,
updateGroupNamePolicy: PermissionPolicy.Admin,
updateGroupPinnedFrameUrlPolicy: PermissionPolicy.Admin,
updateMessageExpirationPolicy: PermissionPolicy.Admin,
});
}
}, [permissionsPolicy]);
Expand Down Expand Up @@ -258,7 +261,7 @@ export const NewConversation: React.FC = () => {
);
}}
data={[
{ value: "0", label: "All members" },
{ value: "0", label: "Default" },
{ value: "1", label: "Admins only" },
{ value: "2", label: "Custom policy" },
]}
Expand Down

0 comments on commit d7031bd

Please sign in to comment.