mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-08 22:45:49 +01:00
✨ Add copy registration token modal
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { Button, Mark, Stack, Text } from '@mantine/core';
|
||||
import { ContextModalProps, modals } from '@mantine/modals';
|
||||
import Link from 'next/link';
|
||||
|
||||
export const CopyRegistrationToken = ({
|
||||
context,
|
||||
id,
|
||||
innerProps,
|
||||
}: ContextModalProps<{ id: string; token: string; expire: Date }>) => {
|
||||
return (
|
||||
<Stack>
|
||||
<Text>
|
||||
Your invitation has been generated. After this modal closes,{' '}
|
||||
<b>you'll not be able to copy this link anymore</b>. If you do no longer wish to invite said
|
||||
person, you can delete this invitation any time.
|
||||
</Text>
|
||||
|
||||
<Link href={`/auth/invite/${innerProps.id}?token=${innerProps.token}`}>Invitation link</Link>
|
||||
|
||||
<Stack spacing="xs">
|
||||
<Text weight="bold">ID:</Text>
|
||||
<Mark style={{ borderRadius: 4 }} color="gray" px={5}>
|
||||
{innerProps.id}
|
||||
</Mark>
|
||||
|
||||
<Text weight="bold">Token:</Text>
|
||||
<Mark style={{ borderRadius: 4 }} color="gray" px={5}>
|
||||
{innerProps.token}
|
||||
</Mark>
|
||||
</Stack>
|
||||
|
||||
<Button
|
||||
onClick={() => {
|
||||
modals.close(id);
|
||||
}}
|
||||
variant="default"
|
||||
fullWidth
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
@@ -14,9 +14,15 @@ export const CreateRegistrationTokenModal = ({
|
||||
}: ContextModalProps<{}>) => {
|
||||
const apiContext = api.useContext();
|
||||
const { isLoading, mutateAsync } = api.registrationTokens.createRegistrationToken.useMutation({
|
||||
onSuccess: async () => {
|
||||
onSuccess: async (data) => {
|
||||
await apiContext.registrationTokens.getAllInvites.invalidate();
|
||||
modals.close(id);
|
||||
|
||||
modals.openContextModal({
|
||||
modal: 'copyRegistrationTokenModal',
|
||||
title: <Text weight="bold">Copy invitation</Text>,
|
||||
innerProps: data,
|
||||
})
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { DeleteUserModal } from './delete-user/delete-user.modal';
|
||||
import { CreateRegistrationTokenModal } from './create-registration-token/create-registration-token.modal';
|
||||
import { DeleteRegistrationTokenModal } from './delete-registration-token/delete-registration-token.modal';
|
||||
import { CreateDashboardModal } from './create-dashboard/create-dashboard.modal';
|
||||
import { CopyRegistrationToken } from './copy-regristration-token/copy-registration-token.modal';
|
||||
|
||||
export const modals = {
|
||||
editApp: EditAppModal,
|
||||
@@ -22,7 +23,8 @@ export const modals = {
|
||||
deleteUserModal: DeleteUserModal,
|
||||
createRegistrationTokenModal: CreateRegistrationTokenModal,
|
||||
deleteRegistrationTokenModal: DeleteRegistrationTokenModal,
|
||||
createDashboardModal: CreateDashboardModal
|
||||
createDashboardModal: CreateDashboardModal,
|
||||
copyRegistrationTokenModal: CopyRegistrationToken,
|
||||
};
|
||||
|
||||
declare module '@mantine/modals' {
|
||||
|
||||
@@ -44,12 +44,18 @@ export const inviteRouter = createTRPCRouter({
|
||||
})
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
await ctx.prisma.registrationToken.create({
|
||||
const token = await ctx.prisma.registrationToken.create({
|
||||
data: {
|
||||
expires: input.expiration,
|
||||
token: randomBytes(20).toString('hex'),
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
id: token.id,
|
||||
token: token.token,
|
||||
expires: token.expires,
|
||||
};
|
||||
}),
|
||||
deleteRegistrationToken: publicProcedure
|
||||
.input(z.object({ tokenId: z.string() }))
|
||||
|
||||
Reference in New Issue
Block a user