@droppii-org/chat-sdk 0.6.52 → 0.6.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"AdminPermissionModal.d.ts","sourceRoot":"","sources":["../../../src/components/group/AdminPermissionModal.tsx"],"names":[],"mappings":"AAaA,UAAU,0BAA0B;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,UAAU,yBAAyB;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IAIpB,MAAM,CAAC,EAAE,OAAO,CAAC;IAGjB,MAAM,CAAC,EAAE,0BAA0B,CAAC;IAKpC,wBAAwB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC5E;AA6DD,QAAA,MAAM,oBAAoB,GAAI,uEAO3B,yBAAyB,mDA2K3B,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"AdminPermissionModal.d.ts","sourceRoot":"","sources":["../../../src/components/group/AdminPermissionModal.tsx"],"names":[],"mappings":"AAqBA,UAAU,0BAA0B;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,UAAU,yBAAyB;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;IAIpB,MAAM,CAAC,EAAE,OAAO,CAAC;IAGjB,MAAM,CAAC,EAAE,0BAA0B,CAAC;IAKpC,wBAAwB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC5E;AAwCD,QAAA,MAAM,oBAAoB,GAAI,uEAO3B,yBAAyB,mDAgK3B,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -5,10 +5,11 @@ import { ConfigProvider, Modal, Switch, message } from "antd";
5
5
  import { useTranslation } from "react-i18next";
6
6
  import { GroupMemberRole } from "@droppii-org/wasm-client-sdk";
7
7
  import { useGroupMembers } from "../../hooks/group/useGroupMembers";
8
- import { useSetGroupMemberPermissions } from "../../hooks/group/useGroupMemberActions";
8
+ import { useSetAdminRolePermissions, useSetGroupMemberPermissions, } from "../../hooks/group/useGroupMemberActions";
9
9
  import { Icon } from "../../components/icon";
10
10
  import { ANTD_PRIMARY_COLOR_VAR } from "../../constants";
11
11
  import { GROUP_PERMISSION_KEY } from "../../constants/im";
12
+ import { changedSwitches, commonSwitchStates, toRolePermissionChange, } from "../../utils/groupPermissionSwitches";
12
13
  // "Cập nhật thông tin nhóm" is one switch in the UI but bundles 3 BE
13
14
  // permission keys (name/avatar/description), so it maps to all three.
14
15
  const UPDATE_GROUP_INFO_KEYS = [
@@ -24,35 +25,21 @@ const SWITCH_PERMISSION_KEYS = {
24
25
  removeMember: [GROUP_PERMISSION_KEY.removeMember],
25
26
  updateGroupInfo: UPDATE_GROUP_INFO_KEYS,
26
27
  };
27
- const SWITCHES = Object.keys(SWITCH_PERMISSION_KEYS);
28
- // A switch reads on only when every given permission list grants all of its keys.
29
- const commonOverrides = (permissionLists) => {
30
- const grants = (name) => permissionLists.length > 0 &&
31
- permissionLists.every((list) => SWITCH_PERMISSION_KEYS[name].every((key) => list.includes(key)));
32
- return {
33
- sendMessage: grants("sendMessage"),
34
- pinMessage: grants("pinMessage"),
35
- viewMemberInformation: grants("viewMemberInformation"),
36
- addMember: grants("addMember"),
37
- removeMember: grants("removeMember"),
38
- updateGroupInfo: grants("updateGroupInfo"),
39
- };
40
- };
41
28
  // Rewrites only the switches that changed; every other key in the list stays as is.
42
29
  const applySwitchChanges = (permissionList, changes) => Object.entries(changes).reduce((list, [name, enabled]) => {
43
30
  const keys = SWITCH_PERMISSION_KEYS[name];
44
31
  const without = list.filter((permission) => !keys.includes(permission));
45
32
  return enabled ? [...without, ...keys] : without;
46
33
  }, permissionList);
47
- const isSamePermissionSet = (a, b) => a.length === b.length && a.every((permission) => b.includes(permission));
48
34
  // "Configure Admin Permissions". With `member` (a member row's … menu) it edits
49
35
  // that one Admin. Without it (the group info panel) it edits every current
50
- // Admin at once: switches start from what the Admins already share, and "Lưu"
51
- // writes only the switches the user flipped, so each Admin keeps the rest.
36
+ // Admin in one setGroupAdminPermissions call: switches start from what the
37
+ // Admins already share, and "Lưu" sends only the switches the user flipped.
52
38
  const AdminPermissionModal = ({ open, groupID, onClose, inline = false, member, onMemberPermissionsSaved, }) => {
53
39
  const { t } = useTranslation();
54
40
  const { members: groupMembers } = useGroupMembers(member ? undefined : groupID);
55
41
  const { mutateAsync: setMemberPermissions } = useSetGroupMemberPermissions();
42
+ const { mutateAsync: setAdminRolePermissions } = useSetAdminRolePermissions();
56
43
  const [isSaving, setIsSaving] = useState(false);
57
44
  const [edits, setEdits] = useState({});
58
45
  useEffect(() => {
@@ -60,19 +47,14 @@ const AdminPermissionModal = ({ open, groupID, onClose, inline = false, member,
60
47
  setEdits({});
61
48
  }, [open, member === null || member === void 0 ? void 0 : member.userID]);
62
49
  const admins = groupMembers.filter((groupMember) => groupMember.roleLevel === GroupMemberRole.Admin);
63
- const baseline = member
64
- ? commonOverrides([member.permissions])
65
- : commonOverrides(admins.map((admin) => { var _a; return (_a = admin.permissions) !== null && _a !== void 0 ? _a : []; }));
50
+ const baseline = commonSwitchStates(SWITCH_PERMISSION_KEYS, member ? [member.permissions] : admins.map((admin) => { var _a; return (_a = admin.permissions) !== null && _a !== void 0 ? _a : []; }));
66
51
  const pending = Object.assign(Object.assign({}, baseline), edits);
67
- const changes = Object.fromEntries(SWITCHES.filter((name) => pending[name] !== baseline[name]).map((name) => [
68
- name,
69
- pending[name],
70
- ]));
52
+ const changes = changedSwitches(baseline, pending);
71
53
  const hasChanges = Object.keys(changes).length > 0;
72
54
  const setSwitch = (name, checked) => setEdits((prev) => (Object.assign(Object.assign({}, prev), { [name]: checked })));
73
55
  const handleSave = async () => {
74
56
  var _a, _b;
75
- if (!groupID)
57
+ if (!groupID || !hasChanges)
76
58
  return;
77
59
  setIsSaving(true);
78
60
  try {
@@ -86,18 +68,7 @@ const AdminPermissionModal = ({ open, groupID, onClose, inline = false, member,
86
68
  onMemberPermissionsSaved === null || onMemberPermissionsSaved === void 0 ? void 0 : onMemberPermissionsSaved(member.userID, nextPermissions);
87
69
  }
88
70
  else {
89
- await Promise.all(admins.map((admin) => {
90
- var _a;
91
- const current = (_a = admin.permissions) !== null && _a !== void 0 ? _a : [];
92
- const nextPermissions = applySwitchChanges(current, changes);
93
- if (isSamePermissionSet(current, nextPermissions))
94
- return undefined;
95
- return setMemberPermissions({
96
- groupID,
97
- userID: admin.userID,
98
- permissions: nextPermissions,
99
- });
100
- }));
71
+ await setAdminRolePermissions(Object.assign({ groupID }, toRolePermissionChange(SWITCH_PERMISSION_KEYS, changes)));
101
72
  }
102
73
  message.success(t("update_admin_permissions_success"));
103
74
  onClose();
@@ -1 +1 @@
1
- {"version":3,"file":"MemberPermissionPanel.d.ts","sourceRoot":"","sources":["../../../src/components/group/MemberPermissionPanel.tsx"],"names":[],"mappings":"AAYA,UAAU,0BAA0B;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAMD,QAAA,MAAM,qBAAqB,GAAI,4BAA4B,0BAA0B,mDAqHpF,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"MemberPermissionPanel.d.ts","sourceRoot":"","sources":["../../../src/components/group/MemberPermissionPanel.tsx"],"names":[],"mappings":"AAkBA,UAAU,0BAA0B;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAuBD,QAAA,MAAM,qBAAqB,GAAI,4BAA4B,0BAA0B,mDA2FpF,CAAC;AAEF,eAAe,qBAAqB,CAAC"}
@@ -3,51 +3,63 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useState } from "react";
4
4
  import { ConfigProvider, Switch, message } from "antd";
5
5
  import { useTranslation } from "react-i18next";
6
- import { useGroupPermission } from "../../hooks/group/useGroupPermission";
6
+ import { GroupMemberRole } from "@droppii-org/wasm-client-sdk";
7
+ import { useGroupMembers } from "../../hooks/group/useGroupMembers";
8
+ import { useSetMemberRolePermissions } from "../../hooks/group/useGroupMemberActions";
7
9
  import { Icon } from "../../components/icon";
8
10
  import { ANTD_PRIMARY_COLOR_VAR } from "../../constants";
9
- import useGroupPermissionOverridesStore from "../../store/groupPermissionOverrides";
10
- // Mocked config UI (DROPPII-30248 follow-up, "Configure Member Permissions")
11
- // — renders inline within the "Thông tin" sidebar (back arrow, no gray
12
- // background) per the reference recording, not as a Modal popup. No BE
13
- // persistence yet, committed to the in-memory override store on "Lưu" only.
11
+ import { GROUP_PERMISSION_KEY } from "../../constants/im";
12
+ import { changedSwitches, commonSwitchStates, toRolePermissionChange, } from "../../utils/groupPermissionSwitches";
13
+ const SWITCH_PERMISSION_KEYS = {
14
+ sendMessage: [GROUP_PERMISSION_KEY.sendMessage],
15
+ addMember: [GROUP_PERMISSION_KEY.addMember],
16
+ pinMessage: [GROUP_PERMISSION_KEY.pinMessage],
17
+ viewMemberInformation: [GROUP_PERMISSION_KEY.viewMemberInformation],
18
+ };
19
+ const SWITCH_LABELS = {
20
+ sendMessage: "permission_send_message",
21
+ addMember: "permission_add_member",
22
+ pinMessage: "permission_pin_message",
23
+ viewMemberInformation: "permission_view_member_info",
24
+ };
25
+ const SWITCHES = Object.keys(SWITCH_PERMISSION_KEYS);
26
+ // "Configure Member Permissions", inline in the "Thông tin" sidebar. Switches
27
+ // start from what every ordinary member already shares, and "Lưu" sends only
28
+ // the switches the user flipped, in one setGroupMemberPermissions call.
14
29
  const MemberPermissionPanel = ({ open, groupID, onClose }) => {
15
30
  const { t } = useTranslation();
16
- const permissions = useGroupPermission(groupID);
17
- const setMemberOverrides = useGroupPermissionOverridesStore((state) => state.setMemberOverrides);
31
+ const { members: groupMembers, isLoading } = useGroupMembers(open ? groupID : undefined);
32
+ const { mutateAsync: setMemberRolePermissions } = useSetMemberRolePermissions();
18
33
  const [isSaving, setIsSaving] = useState(false);
19
- const [pending, setPending] = useState({
20
- sendMessage: permissions.sendMessage,
21
- addMember: permissions.addMember,
22
- pinMessage: permissions.pinMessage,
23
- viewMemberInformation: permissions.viewMemberInformation,
24
- });
34
+ const [edits, setEdits] = useState({});
25
35
  useEffect(() => {
26
- if (!open)
27
- return;
28
- setPending({
29
- sendMessage: permissions.sendMessage,
30
- addMember: permissions.addMember,
31
- pinMessage: permissions.pinMessage,
32
- viewMemberInformation: permissions.viewMemberInformation,
33
- });
34
- // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ if (open)
37
+ setEdits({});
35
38
  }, [open]);
36
- const hasChanges = pending.sendMessage !== permissions.sendMessage ||
37
- pending.addMember !== permissions.addMember ||
38
- pending.pinMessage !== permissions.pinMessage ||
39
- pending.viewMemberInformation !== permissions.viewMemberInformation;
39
+ const members = groupMembers.filter((groupMember) => groupMember.roleLevel === GroupMemberRole.Normal);
40
+ const baseline = commonSwitchStates(SWITCH_PERMISSION_KEYS, members.map((member) => { var _a; return (_a = member.permissions) !== null && _a !== void 0 ? _a : []; }));
41
+ const pending = Object.assign(Object.assign({}, baseline), edits);
42
+ const changes = changedSwitches(baseline, pending);
43
+ const hasChanges = Object.keys(changes).length > 0;
40
44
  const handleSave = async () => {
41
- if (!groupID)
45
+ if (!groupID || !hasChanges)
42
46
  return;
43
47
  setIsSaving(true);
44
- setMemberOverrides(groupID, pending);
45
- message.success(t("update_member_permissions_success"));
46
- setIsSaving(false);
47
- onClose();
48
+ try {
49
+ await setMemberRolePermissions(Object.assign({ groupID }, toRolePermissionChange(SWITCH_PERMISSION_KEYS, changes)));
50
+ message.success(t("update_member_permissions_success"));
51
+ onClose();
52
+ }
53
+ catch (error) {
54
+ console.error("setGroupMemberPermissions", error);
55
+ message.error(t("update_member_permissions_failed"));
56
+ }
57
+ finally {
58
+ setIsSaving(false);
59
+ }
48
60
  };
49
61
  if (!open)
50
62
  return null;
51
- return (_jsxs("div", { className: "absolute inset-0 bg-white flex flex-col z-10", "data-cp-name": "MemberPermissionPanel", children: [_jsxs("div", { className: "flex w-full items-center border-b border-gray-100 p-2", children: [_jsx("button", { type: "button", className: "flex shrink-0 cursor-pointer items-center justify-center p-2 text-[var(--dc-color-nav-icon)]", onClick: onClose, children: _jsx(Icon, { icon: "arrow-left-o", size: 24 }) }), _jsx("p", { className: "min-w-0 flex-1 truncate px-2 text-[18px] font-bold leading-[1.6] text-gray-900", children: t("member_permission_settings") })] }), _jsx("div", { className: "flex-1 overflow-y-auto", children: _jsx(ConfigProvider, { theme: { token: { colorPrimary: ANTD_PRIMARY_COLOR_VAR } }, children: _jsxs("div", { className: "flex flex-col py-2", children: [_jsxs("div", { className: "flex items-center justify-between px-4 py-3", children: [_jsx("span", { className: "text-sm", children: t("permission_send_message") }), _jsx(Switch, { checked: pending.sendMessage, onChange: (checked) => setPending((prev) => (Object.assign(Object.assign({}, prev), { sendMessage: checked }))) })] }), _jsxs("div", { className: "flex items-center justify-between px-4 py-3", children: [_jsx("span", { className: "text-sm", children: t("permission_add_member") }), _jsx(Switch, { checked: pending.addMember, onChange: (checked) => setPending((prev) => (Object.assign(Object.assign({}, prev), { addMember: checked }))) })] }), _jsxs("div", { className: "flex items-center justify-between px-4 py-3", children: [_jsx("span", { className: "text-sm", children: t("permission_pin_message") }), _jsx(Switch, { checked: pending.pinMessage, onChange: (checked) => setPending((prev) => (Object.assign(Object.assign({}, prev), { pinMessage: checked }))) })] }), _jsxs("div", { className: "flex items-center justify-between px-4 py-3", children: [_jsx("span", { className: "text-sm", children: t("permission_view_member_info") }), _jsx(Switch, { checked: pending.viewMemberInformation, onChange: (checked) => setPending((prev) => (Object.assign(Object.assign({}, prev), { viewMemberInformation: checked }))) })] })] }) }) }), _jsxs("div", { className: "flex items-center justify-end gap-2 px-4 py-3 border-t border-gray-100", children: [_jsx("button", { type: "button", className: "px-4 py-1.5 rounded-full border border-gray-300 text-gray-700 text-sm font-medium", onClick: onClose, children: t("cancel") }), _jsx("button", { type: "button", className: "px-4 py-1.5 rounded-full bg-[var(--dc-color-primary)] text-white text-sm font-medium disabled:bg-gray-200 disabled:text-gray-400", disabled: !hasChanges || isSaving, onClick: handleSave, children: t("save") })] })] }));
63
+ return (_jsxs("div", { className: "absolute inset-0 bg-white flex flex-col z-10", "data-cp-name": "MemberPermissionPanel", children: [_jsxs("div", { className: "flex w-full items-center border-b border-gray-100 p-2", children: [_jsx("button", { type: "button", className: "flex shrink-0 cursor-pointer items-center justify-center p-2 text-[var(--dc-color-nav-icon)]", onClick: onClose, children: _jsx(Icon, { icon: "arrow-left-o", size: 24 }) }), _jsx("p", { className: "min-w-0 flex-1 truncate px-2 text-[18px] font-bold leading-[1.6] text-gray-900", children: t("member_permission_settings") })] }), _jsx("div", { className: "flex-1 overflow-y-auto", children: _jsx(ConfigProvider, { theme: { token: { colorPrimary: ANTD_PRIMARY_COLOR_VAR } }, children: _jsx("div", { className: "flex flex-col py-2", children: SWITCHES.map((name) => (_jsxs("div", { className: "flex items-center justify-between px-4 py-3", children: [_jsx("span", { className: "text-sm", children: t(SWITCH_LABELS[name]) }), _jsx(Switch, { checked: pending[name], disabled: isLoading, onChange: (checked) => setEdits((prev) => (Object.assign(Object.assign({}, prev), { [name]: checked }))) })] }, name))) }) }) }), _jsxs("div", { className: "flex items-center justify-end gap-2 px-4 py-3 border-t border-gray-100", children: [_jsx("button", { type: "button", className: "px-4 py-1.5 rounded-full border border-gray-300 text-gray-700 text-sm font-medium", onClick: onClose, children: t("cancel") }), _jsx("button", { type: "button", className: "px-4 py-1.5 rounded-full bg-[var(--dc-color-primary)] text-white text-sm font-medium disabled:bg-gray-200 disabled:text-gray-400", disabled: !hasChanges || isSaving || isLoading, onClick: handleSave, children: t("save") })] })] }));
52
64
  };
53
65
  export default MemberPermissionPanel;
@@ -27,5 +27,12 @@ interface SetGroupMemberPermissionsParams {
27
27
  permissions: string[];
28
28
  }
29
29
  export declare const useSetGroupMemberPermissions: () => import("@tanstack/react-query").UseMutationResult<unknown, Error, SetGroupMemberPermissionsParams, unknown>;
30
+ interface SetRolePermissionsParams {
31
+ groupID: string;
32
+ enablePermissions: string[];
33
+ disablePermissions: string[];
34
+ }
35
+ export declare const useSetAdminRolePermissions: () => import("@tanstack/react-query").UseMutationResult<unknown, Error, SetRolePermissionsParams, unknown>;
36
+ export declare const useSetMemberRolePermissions: () => import("@tanstack/react-query").UseMutationResult<unknown, Error, SetRolePermissionsParams, unknown>;
30
37
  export {};
31
38
  //# sourceMappingURL=useGroupMemberActions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useGroupMemberActions.d.ts","sourceRoot":"","sources":["../../../src/hooks/group/useGroupMemberActions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAmB,MAAM,8BAA8B,CAAC;AAQhF,UAAU,qBAAqB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf;AAED,eAAO,MAAM,kBAAkB,yGAW9B,CAAC;AAEF,UAAU,qBAAqB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,kBAAkB,yGAW9B,CAAC;AAEF,UAAU,wBAAwB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,eAAe,CAAC;CAC5B;AAED,eAAO,MAAM,qBAAqB,4GAWjC,CAAC;AAEF,UAAU,wBAAwB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,qBAAqB,4GAUjC,CAAC;AAEF,UAAU,+BAA+B;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,eAAO,MAAM,4BAA4B,mHAexC,CAAC"}
1
+ {"version":3,"file":"useGroupMemberActions.d.ts","sourceRoot":"","sources":["../../../src/hooks/group/useGroupMemberActions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAmB,MAAM,8BAA8B,CAAC;AAQhF,UAAU,qBAAqB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf;AAED,eAAO,MAAM,kBAAkB,yGAW9B,CAAC;AAEF,UAAU,qBAAqB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,kBAAkB,yGAW9B,CAAC;AAEF,UAAU,wBAAwB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,eAAe,CAAC;CAC5B;AAED,eAAO,MAAM,qBAAqB,4GAWjC,CAAC;AAEF,UAAU,wBAAwB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,eAAO,MAAM,qBAAqB,4GAUjC,CAAC;AAEF,UAAU,+BAA+B;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,eAAO,MAAM,4BAA4B,mHAexC,CAAC;AAEF,UAAU,wBAAwB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,kBAAkB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAaD,eAAO,MAAM,0BAA0B,4GAOtC,CAAC;AAGF,eAAO,MAAM,2BAA2B,4GAOvC,CAAC"}
@@ -64,3 +64,26 @@ export const useSetGroupMemberPermissions = () => {
64
64
  },
65
65
  });
66
66
  };
67
+ const toRolePermissionsReq = ({ groupID, enablePermissions, disablePermissions, }) => ({
68
+ groupID,
69
+ enablePermissions: enablePermissions,
70
+ disablePermissions: disablePermissions,
71
+ });
72
+ // One call for every Admin of the group; each Admin keeps the keys not listed.
73
+ export const useSetAdminRolePermissions = () => {
74
+ return useMutation({
75
+ mutationFn: async (params) => {
76
+ const { data } = await DChatSDK.setGroupAdminPermissions(toRolePermissionsReq(params));
77
+ return data;
78
+ },
79
+ });
80
+ };
81
+ // One call for every ordinary member of the group; each keeps the keys not listed.
82
+ export const useSetMemberRolePermissions = () => {
83
+ return useMutation({
84
+ mutationFn: async (params) => {
85
+ const { data } = await DChatSDK.setGroupMemberPermissions(toRolePermissionsReq(params));
86
+ return data;
87
+ },
88
+ });
89
+ };
@@ -253,6 +253,7 @@
253
253
  "permission_remove_member": "Xoá thành viên",
254
254
  "permission_update_group_info": "Cập nhật thông tin nhóm",
255
255
  "update_member_permissions_success": "Cập nhật quyền thành viên thành công",
256
+ "update_member_permissions_failed": "Cập nhật quyền thành viên thất bại",
256
257
  "update_admin_permissions_success": "Cập nhật quyền quản trị viên thành công",
257
258
  "invite_via_link": "Mời vào nhóm bằng link",
258
259
  "invite_link_empty_owner_title": "Tạo link tham gia nhóm",
@@ -0,0 +1,9 @@
1
+ export type PermissionSwitchKeys<S extends string> = Record<S, readonly string[]>;
2
+ export type SwitchStates<S extends string> = Record<S, boolean>;
3
+ export declare const commonSwitchStates: <S extends string>(switchKeys: PermissionSwitchKeys<S>, permissionLists: string[][]) => SwitchStates<S>;
4
+ export declare const changedSwitches: <S extends string>(baseline: SwitchStates<S>, pending: SwitchStates<S>) => Partial<SwitchStates<S>>;
5
+ export declare const toRolePermissionChange: <S extends string>(switchKeys: PermissionSwitchKeys<S>, changes: Partial<SwitchStates<S>>) => {
6
+ enablePermissions: string[];
7
+ disablePermissions: string[];
8
+ };
9
+ //# sourceMappingURL=groupPermissionSwitches.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groupPermissionSwitches.d.ts","sourceRoot":"","sources":["../../src/utils/groupPermissionSwitches.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;AAClF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AAGhE,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,MAAM,EACjD,YAAY,oBAAoB,CAAC,CAAC,CAAC,EACnC,iBAAiB,MAAM,EAAE,EAAE,KAC1B,YAAY,CAAC,CAAC,CASK,CAAC;AAGvB,eAAO,MAAM,eAAe,GAAI,CAAC,SAAS,MAAM,EAC9C,UAAU,YAAY,CAAC,CAAC,CAAC,EACzB,SAAS,YAAY,CAAC,CAAC,CAAC,KACvB,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAKK,CAAC;AAGhC,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,MAAM,EACrD,YAAY,oBAAoB,CAAC,CAAC,CAAC,EACnC,SAAS,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;;;CAQlC,CAAC"}
@@ -0,0 +1,19 @@
1
+ // A switch reads on only when every given permission list grants all of its keys.
2
+ export const commonSwitchStates = (switchKeys, permissionLists) => Object.fromEntries(Object.keys(switchKeys).map((name) => [
3
+ name,
4
+ permissionLists.length > 0 &&
5
+ permissionLists.every((list) => switchKeys[name].every((key) => list.includes(key))),
6
+ ]));
7
+ // The switches whose pending value differs from the baseline, with their new value.
8
+ export const changedSwitches = (baseline, pending) => Object.fromEntries(Object.keys(baseline)
9
+ .filter((name) => pending[name] !== baseline[name])
10
+ .map((name) => [name, pending[name]]));
11
+ // Splits the flipped switches into the enable/disable key lists of a role-wide update.
12
+ export const toRolePermissionChange = (switchKeys, changes) => {
13
+ const enablePermissions = [];
14
+ const disablePermissions = [];
15
+ Object.entries(changes).forEach(([name, enabled]) => {
16
+ (enabled ? enablePermissions : disablePermissions).push(...switchKeys[name]);
17
+ });
18
+ return { enablePermissions, disablePermissions };
19
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@droppii-org/chat-sdk",
3
- "version": "0.6.52",
3
+ "version": "0.6.53",
4
4
  "description": "Droppii React Chat SDK",
5
5
  "repository": {
6
6
  "type": "git",
@@ -85,7 +85,7 @@
85
85
  "dependencies": {
86
86
  "@ant-design/cssinjs": "^1.24.0",
87
87
  "@ant-design/icons": "^6.0.0",
88
- "@droppii-org/wasm-client-sdk": "0.6.0",
88
+ "@droppii-org/wasm-client-sdk": "0.7.0",
89
89
  "@lexical/code": "^0.34.0",
90
90
  "@lexical/html": "^0.34.0",
91
91
  "@lexical/link": "^0.34.0",
@@ -1,23 +0,0 @@
1
- export interface MemberPermissionOverrides {
2
- sendMessage: boolean;
3
- addMember: boolean;
4
- pinMessage: boolean;
5
- viewMemberInformation: boolean;
6
- }
7
- export interface AdminPermissionOverrides {
8
- sendMessage: boolean;
9
- pinMessage: boolean;
10
- viewMemberInformation: boolean;
11
- addMember: boolean;
12
- removeMember: boolean;
13
- updateGroupInfo: boolean;
14
- }
15
- interface GroupPermissionOverridesStore {
16
- memberOverridesByGroup: Record<string, MemberPermissionOverrides>;
17
- adminOverridesByGroup: Record<string, AdminPermissionOverrides>;
18
- setMemberOverrides: (groupID: string, overrides: MemberPermissionOverrides) => void;
19
- setAdminOverrides: (groupID: string, overrides: AdminPermissionOverrides) => void;
20
- }
21
- declare const useGroupPermissionOverridesStore: import("zustand").UseBoundStore<import("zustand").StoreApi<GroupPermissionOverridesStore>>;
22
- export default useGroupPermissionOverridesStore;
23
- //# sourceMappingURL=groupPermissionOverrides.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"groupPermissionOverrides.d.ts","sourceRoot":"","sources":["../../src/store/groupPermissionOverrides.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,qBAAqB,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,UAAU,6BAA6B;IACrC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;IAClE,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IAChE,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,yBAAyB,KAAK,IAAI,CAAC;IACpF,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,wBAAwB,KAAK,IAAI,CAAC;CACnF;AAED,QAAA,MAAM,gCAAgC,4FAmBrC,CAAC;AAEF,eAAe,gCAAgC,CAAC"}
@@ -1,12 +0,0 @@
1
- import { create } from "zustand";
2
- const useGroupPermissionOverridesStore = create((set) => ({
3
- memberOverridesByGroup: {},
4
- adminOverridesByGroup: {},
5
- setMemberOverrides: (groupID, overrides) => set((state) => ({
6
- memberOverridesByGroup: Object.assign(Object.assign({}, state.memberOverridesByGroup), { [groupID]: overrides }),
7
- })),
8
- setAdminOverrides: (groupID, overrides) => set((state) => ({
9
- adminOverridesByGroup: Object.assign(Object.assign({}, state.adminOverridesByGroup), { [groupID]: overrides }),
10
- })),
11
- }));
12
- export default useGroupPermissionOverridesStore;