From 705dcd001b65ccc6049f5e1c661c9a01c2b4deca Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Wed, 6 Jul 2022 12:49:24 +0100 Subject: [PATCH] feat: add correct submit buttons to form modals --- package.json | 2 +- .../modals/components/AddFriend.tsx | 5 ++ .../modals/components/BanMember.tsx | 4 ++ .../modals/components/Confirmation.tsx | 6 ++ .../modals/components/CreateCategory.tsx | 3 + .../modals/components/CreateChannel.tsx | 3 + .../modals/components/CreateGroup.tsx | 3 + .../modals/components/CreateInvite.tsx | 12 ++++ .../modals/components/CreateRole.tsx | 3 + .../modals/components/CreateServer.tsx | 3 + .../modals/components/CustomStatus.tsx | 3 + .../modals/components/DeleteMessage.tsx | 4 ++ .../modals/components/ImportTheme.tsx | 3 + .../modals/components/KickMember.tsx | 4 ++ src/lib/ContextMenus.tsx | 57 ++++++++++--------- yarn.lock | 10 ++-- 16 files changed, 91 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index ddc93912..5fcf312b 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "@hcaptcha/react-hcaptcha": "^0.3.6", "@insertish/vite-plugin-babel-macros": "^1.0.5", "@preact/preset-vite": "^2.0.0", - "@revoltchat/ui": "1.0.65", + "@revoltchat/ui": "1.0.69", "@rollup/plugin-replace": "^2.4.2", "@styled-icons/boxicons-logos": "^10.38.0", "@styled-icons/boxicons-regular": "^10.38.0", diff --git a/src/controllers/modals/components/AddFriend.tsx b/src/controllers/modals/components/AddFriend.tsx index e239012b..c2b61f90 100644 --- a/src/controllers/modals/components/AddFriend.tsx +++ b/src/controllers/modals/components/AddFriend.tsx @@ -1,3 +1,5 @@ +import { Text } from "preact-i18n"; + import { ModalForm } from "@revoltchat/ui"; import { noop } from "../../../lib/js"; @@ -26,6 +28,9 @@ export default function AddFriend({ ...props }: ModalProps<"add_friend">) { callback={({ username }) => client.api.post(`/users/friend`, { username }).then(noop) } + submit={{ + children: , + }} /> ); } diff --git a/src/controllers/modals/components/BanMember.tsx b/src/controllers/modals/components/BanMember.tsx index 640d9ce9..2c5b3278 100644 --- a/src/controllers/modals/components/BanMember.tsx +++ b/src/controllers/modals/components/BanMember.tsx @@ -41,6 +41,10 @@ export default function BanMember({ callback={async ({ reason }) => void (await member.server!.banUser(member._id.user, { reason })) } + submit={{ + palette: "error", + children: , + }} /> ); } diff --git a/src/controllers/modals/components/Confirmation.tsx b/src/controllers/modals/components/Confirmation.tsx index aba1c294..5e7977c9 100644 --- a/src/controllers/modals/components/Confirmation.tsx +++ b/src/controllers/modals/components/Confirmation.tsx @@ -96,6 +96,12 @@ export default function Confirmation( break; } }} + submit={{ + palette: "error", + children: ( + + ), + }} /> ); } diff --git a/src/controllers/modals/components/CreateCategory.tsx b/src/controllers/modals/components/CreateCategory.tsx index 23cf7298..e18aa7a9 100644 --- a/src/controllers/modals/components/CreateCategory.tsx +++ b/src/controllers/modals/components/CreateCategory.tsx @@ -39,6 +39,9 @@ export default function CreateCategory({ ], }); }} + submit={{ + children: , + }} /> ); } diff --git a/src/controllers/modals/components/CreateChannel.tsx b/src/controllers/modals/components/CreateChannel.tsx index c9ffbdad..e1d00e65 100644 --- a/src/controllers/modals/components/CreateChannel.tsx +++ b/src/controllers/modals/components/CreateChannel.tsx @@ -67,6 +67,9 @@ export default function CreateChannel({ ); } }} + submit={{ + children: , + }} /> ); } diff --git a/src/controllers/modals/components/CreateGroup.tsx b/src/controllers/modals/components/CreateGroup.tsx index 797e23e0..af3b96c7 100644 --- a/src/controllers/modals/components/CreateGroup.tsx +++ b/src/controllers/modals/components/CreateGroup.tsx @@ -40,6 +40,9 @@ export default function CreateGroup({ ...props }: ModalProps<"create_group">) { history.push(`/channel/${group._id}`); }} + submit={{ + children: , + }} /> ); } diff --git a/src/controllers/modals/components/CreateInvite.tsx b/src/controllers/modals/components/CreateInvite.tsx index a2ddbd95..d070c08f 100644 --- a/src/controllers/modals/components/CreateInvite.tsx +++ b/src/controllers/modals/components/CreateInvite.tsx @@ -71,6 +71,18 @@ export default function CreateInvite({ }, }} callback={noopAsync} + submit={{ + children: , + }} + actions={[ + { + children: , + onClick: () => + modalController.writeText( + `${window.location.protocol}//${window.location.host}/invite/${code}`, + ), + }, + ]} /> ); } diff --git a/src/controllers/modals/components/CreateRole.tsx b/src/controllers/modals/components/CreateRole.tsx index 4ce5d038..51692bef 100644 --- a/src/controllers/modals/components/CreateRole.tsx +++ b/src/controllers/modals/components/CreateRole.tsx @@ -30,6 +30,9 @@ export default function CreateRole({ const role = await server.createRole(name); callback(role.id); }} + submit={{ + children: , + }} /> ); } diff --git a/src/controllers/modals/components/CreateServer.tsx b/src/controllers/modals/components/CreateServer.tsx index b6f6a374..08da9c91 100644 --- a/src/controllers/modals/components/CreateServer.tsx +++ b/src/controllers/modals/components/CreateServer.tsx @@ -52,6 +52,9 @@ export default function CreateServer({ history.push(`/server/${server._id}`); }} + submit={{ + children: , + }} /> ); } diff --git a/src/controllers/modals/components/CustomStatus.tsx b/src/controllers/modals/components/CustomStatus.tsx index 7db3ddac..4b72ae77 100644 --- a/src/controllers/modals/components/CustomStatus.tsx +++ b/src/controllers/modals/components/CustomStatus.tsx @@ -38,6 +38,9 @@ export default function CustomStatus({ }, }) } + submit={{ + children: , + }} /> ); } diff --git a/src/controllers/modals/components/DeleteMessage.tsx b/src/controllers/modals/components/DeleteMessage.tsx index 6dbf95c4..29f94746 100644 --- a/src/controllers/modals/components/DeleteMessage.tsx +++ b/src/controllers/modals/components/DeleteMessage.tsx @@ -30,6 +30,10 @@ export default function DeleteMessage({ }, }} callback={() => target.delete()} + submit={{ + palette: "error", + children: , + }} /> ); } diff --git a/src/controllers/modals/components/ImportTheme.tsx b/src/controllers/modals/components/ImportTheme.tsx index 67071e61..b76c7634 100644 --- a/src/controllers/modals/components/ImportTheme.tsx +++ b/src/controllers/modals/components/ImportTheme.tsx @@ -27,6 +27,9 @@ export default function ImportTheme({ ...props }: ModalProps<"import_theme">) { callback={async ({ data }) => state.settings.theme.hydrate(JSON.parse(data)) } + submit={{ + children: , + }} /> ); } diff --git a/src/controllers/modals/components/KickMember.tsx b/src/controllers/modals/components/KickMember.tsx index 8631d519..213850cc 100644 --- a/src/controllers/modals/components/KickMember.tsx +++ b/src/controllers/modals/components/KickMember.tsx @@ -33,6 +33,10 @@ export default function KickMember({ }, }} callback={() => member.kick()} + submit={{ + palette: "error", + children: , + }} /> ); } diff --git a/src/lib/ContextMenus.tsx b/src/lib/ContextMenus.tsx index ac080531..b75eed1a 100644 --- a/src/lib/ContextMenus.tsx +++ b/src/lib/ContextMenus.tsx @@ -669,35 +669,36 @@ export default function ContextMenus() { userId !== uid && uid !== server.owner ) { - if (serverPermissions & Permission.KickMembers) - generateAction( - { - action: "kick_member", - target: client.members.getKey({ - server: server._id, - user: user!._id, - })!, - }, - undefined, // this is needed because generateAction uses positional, not named parameters - undefined, - null, - "var(--error)", // the only relevant part really - ); + const member = client.members.getKey({ + server: server._id, + user: user!._id, + })!; - if (serverPermissions & Permission.BanMembers) - generateAction( - { - action: "ban_member", - target: client.members.getKey({ - server: server._id, - user: user!._id, - })!, - }, - undefined, - undefined, - null, - "var(--error)", - ); + if (member) { + if (serverPermissions & Permission.KickMembers) + generateAction( + { + action: "kick_member", + target: member, + }, + undefined, // this is needed because generateAction uses positional, not named parameters + undefined, + null, + "var(--error)", // the only relevant part really + ); + + if (serverPermissions & Permission.BanMembers) + generateAction( + { + action: "ban_member", + target: member, + }, + undefined, + undefined, + null, + "var(--error)", + ); + } } } diff --git a/yarn.lock b/yarn.lock index 5d8aca1b..cd804219 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2231,9 +2231,9 @@ __metadata: languageName: node linkType: hard -"@revoltchat/ui@npm:1.0.65": - version: 1.0.65 - resolution: "@revoltchat/ui@npm:1.0.65" +"@revoltchat/ui@npm:1.0.69": + version: 1.0.69 + resolution: "@revoltchat/ui@npm:1.0.69" dependencies: "@styled-icons/boxicons-logos": ^10.38.0 "@styled-icons/boxicons-regular": ^10.38.0 @@ -2247,7 +2247,7 @@ __metadata: react-virtuoso: ^2.12.0 peerDependencies: revolt.js: "*" - checksum: 34a52672aa3aca1c62d884c62f2c85c0100b6adb21b7d01053e74e96cfa95cb76f125e1ca1f46afc586a8730b273746486525199f66969338e6c84ab1f21e7cd + checksum: bb67870911689d7dccd82f96affdb0e3e89b2e688d4a7403ee9bbb6a0245dfc296f35636ababd5ed6b43a3ce26777cee03c453728088b4a29fed350dcc89ea37 languageName: node linkType: hard @@ -3554,7 +3554,7 @@ __metadata: "@hcaptcha/react-hcaptcha": ^0.3.6 "@insertish/vite-plugin-babel-macros": ^1.0.5 "@preact/preset-vite": ^2.0.0 - "@revoltchat/ui": 1.0.65 + "@revoltchat/ui": 1.0.69 "@rollup/plugin-replace": ^2.4.2 "@styled-icons/boxicons-logos": ^10.38.0 "@styled-icons/boxicons-regular": ^10.38.0