feat: add correct submit buttons to form modals

This commit is contained in:
Paul Makles
2022-07-06 12:49:24 +01:00
parent f9c6f5cd9d
commit 705dcd001b
16 changed files with 91 additions and 34 deletions

View File

@@ -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: <Text id="app.special.modals.actions.ok" />,
}}
/>
);
}

View File

@@ -41,6 +41,10 @@ export default function BanMember({
callback={async ({ reason }) =>
void (await member.server!.banUser(member._id.user, { reason }))
}
submit={{
palette: "error",
children: <Text id="app.special.modals.actions.ban" />,
}}
/>
);
}

View File

@@ -96,6 +96,12 @@ export default function Confirmation(
break;
}
}}
submit={{
palette: "error",
children: (
<Text id={`app.special.modals.actions.${event[1]}`} />
),
}}
/>
);
}

View File

@@ -39,6 +39,9 @@ export default function CreateCategory({
],
});
}}
submit={{
children: <Text id="app.special.modals.actions.create" />,
}}
/>
);
}

View File

@@ -67,6 +67,9 @@ export default function CreateChannel({
);
}
}}
submit={{
children: <Text id="app.special.modals.actions.create" />,
}}
/>
);
}

View File

@@ -40,6 +40,9 @@ export default function CreateGroup({ ...props }: ModalProps<"create_group">) {
history.push(`/channel/${group._id}`);
}}
submit={{
children: <Text id="app.special.modals.actions.create" />,
}}
/>
);
}

View File

@@ -71,6 +71,18 @@ export default function CreateInvite({
},
}}
callback={noopAsync}
submit={{
children: <Text id="app.special.modals.actions.ok" />,
}}
actions={[
{
children: <Text id="app.context_menu.copy_link" />,
onClick: () =>
modalController.writeText(
`${window.location.protocol}//${window.location.host}/invite/${code}`,
),
},
]}
/>
);
}

View File

@@ -30,6 +30,9 @@ export default function CreateRole({
const role = await server.createRole(name);
callback(role.id);
}}
submit={{
children: <Text id="app.special.modals.actions.create" />,
}}
/>
);
}

View File

@@ -52,6 +52,9 @@ export default function CreateServer({
history.push(`/server/${server._id}`);
}}
submit={{
children: <Text id="app.special.modals.actions.create" />,
}}
/>
);
}

View File

@@ -38,6 +38,9 @@ export default function CustomStatus({
},
})
}
submit={{
children: <Text id="app.special.modals.actions.save" />,
}}
/>
);
}

View File

@@ -30,6 +30,10 @@ export default function DeleteMessage({
},
}}
callback={() => target.delete()}
submit={{
palette: "error",
children: <Text id="app.special.modals.actions.delete" />,
}}
/>
);
}

View File

@@ -27,6 +27,9 @@ export default function ImportTheme({ ...props }: ModalProps<"import_theme">) {
callback={async ({ data }) =>
state.settings.theme.hydrate(JSON.parse(data))
}
submit={{
children: <Text id="app.special.modals.actions.ok" />,
}}
/>
);
}

View File

@@ -33,6 +33,10 @@ export default function KickMember({
},
}}
callback={() => member.kick()}
submit={{
palette: "error",
children: <Text id="app.special.modals.actions.kick" />,
}}
/>
);
}

View File

@@ -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)",
);
}
}
}