♻️ Rename registration token to invite, add created by
This commit is contained in:
@@ -8,17 +8,17 @@ import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
|
||||
import { useRouter } from 'next/router';
|
||||
import { z } from 'zod';
|
||||
import { prisma } from '~/server/db';
|
||||
import { registerNamespaces } from '~/tools/server/translation-namespaces';
|
||||
import { inviteNamespaces } from '~/tools/server/translation-namespaces';
|
||||
import { api } from '~/utils/api';
|
||||
import { useI18nZodResolver } from '~/utils/i18n-zod-resolver';
|
||||
import { signUpFormSchema } from '~/validations/user';
|
||||
|
||||
export default function AuthInvitePage() {
|
||||
const { t } = useTranslation('authentication/register');
|
||||
const { t } = useTranslation('authentication/invite');
|
||||
const { i18nZodResolver } = useI18nZodResolver();
|
||||
const router = useRouter();
|
||||
const query = router.query as { token: string };
|
||||
const { mutateAsync } = api.user.register.useMutation();
|
||||
const { mutateAsync } = api.user.createFromInvite.useMutation();
|
||||
|
||||
const form = useForm<z.infer<typeof signUpFormSchema>>({
|
||||
validateInputOnChange: true,
|
||||
@@ -37,7 +37,7 @@ export default function AuthInvitePage() {
|
||||
void mutateAsync(
|
||||
{
|
||||
...values,
|
||||
registerToken: query.token,
|
||||
inviteToken: query.token,
|
||||
},
|
||||
{
|
||||
onSuccess() {
|
||||
@@ -124,7 +124,7 @@ export const getServerSideProps: GetServerSideProps = async ({ locale, query, pa
|
||||
};
|
||||
}
|
||||
|
||||
const token = await prisma.registrationToken.findUnique({
|
||||
const token = await prisma.invite.findUnique({
|
||||
where: {
|
||||
id: routeParams.data.inviteId,
|
||||
token: queryParams.data.token,
|
||||
@@ -139,7 +139,7 @@ export const getServerSideProps: GetServerSideProps = async ({ locale, query, pa
|
||||
|
||||
return {
|
||||
props: {
|
||||
...(await serverSideTranslations(locale ?? '', registerNamespaces)),
|
||||
...(await serverSideTranslations(locale ?? '', inviteNamespaces)),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -49,9 +49,9 @@ const CreateNewUserPage = () => {
|
||||
});
|
||||
|
||||
const context = api.useContext();
|
||||
const { mutateAsync, isLoading } = api.user.createUser.useMutation({
|
||||
const { mutateAsync, isLoading } = api.user.create.useMutation({
|
||||
onSettled: () => {
|
||||
void context.user.getAll.invalidate();
|
||||
void context.user.all.invalidate();
|
||||
},
|
||||
onSuccess: () => {
|
||||
nextStep();
|
||||
|
||||
@@ -24,7 +24,7 @@ const ManageUsersPage = () => {
|
||||
const [activePage, setActivePage] = useState(0);
|
||||
const [nonDebouncedSearch, setNonDebouncedSearch] = useState<string | undefined>('');
|
||||
const [debouncedSearch] = useDebouncedValue<string | undefined>(nonDebouncedSearch, 200);
|
||||
const { data } = api.user.getAll.useQuery({
|
||||
const { data } = api.user.all.useQuery({
|
||||
page: activePage,
|
||||
search: debouncedSearch,
|
||||
});
|
||||
|
||||
@@ -19,7 +19,7 @@ import { api } from '~/utils/api';
|
||||
|
||||
const ManageUserInvitesPage = () => {
|
||||
const [activePage, setActivePage] = useState(0);
|
||||
const { data } = api.registrationTokens.getAllInvites.useQuery({
|
||||
const { data } = api.invites.all.useQuery({
|
||||
page: activePage,
|
||||
});
|
||||
|
||||
@@ -40,17 +40,17 @@ const ManageUserInvitesPage = () => {
|
||||
</Head>
|
||||
<Title mb="md">Manage user invites</Title>
|
||||
<Text mb="xl">
|
||||
Using registration tokens, you can invite users to your Homarr instance. An invitation will
|
||||
only be valid for a certain time-span and can be used once. The expiration must be between 5
|
||||
minutes and 12 months upon creation.
|
||||
Using invites, you can invite users to your Homarr instance. An invitation will only be
|
||||
valid for a certain time-span and can be used once. The expiration must be between 5 minutes
|
||||
and 12 months upon creation.
|
||||
</Text>
|
||||
|
||||
<Flex justify="end" mb="md">
|
||||
<Button
|
||||
onClick={() => {
|
||||
modals.openContextModal({
|
||||
modal: 'createRegistrationTokenModal',
|
||||
title: 'Create registration token',
|
||||
modal: 'createInviteModal',
|
||||
title: 'Create invite',
|
||||
innerProps: {},
|
||||
});
|
||||
}}
|
||||
@@ -67,31 +67,35 @@ const ManageUserInvitesPage = () => {
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Creator</th>
|
||||
<th>Expires</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.registrationTokens.map((token, index) => (
|
||||
{data.invites.map((invite, index) => (
|
||||
<tr key={index}>
|
||||
<td className={classes.tableIdCell}>
|
||||
<Text lineClamp={1}>{token.id}</Text>
|
||||
<td className={classes.tableGrowCell}>
|
||||
<Text lineClamp={1}>{invite.id}</Text>
|
||||
</td>
|
||||
<td className={classes.tableGrowCell}>
|
||||
<Text lineClamp={1}>{invite.creator}</Text>
|
||||
</td>
|
||||
<td className={classes.tableCell}>
|
||||
{dayjs(dayjs()).isAfter(token.expires) ? (
|
||||
<Text>expired {dayjs(token.expires).fromNow()}</Text>
|
||||
{dayjs(dayjs()).isAfter(invite.expires) ? (
|
||||
<Text>expired {dayjs(invite.expires).fromNow()}</Text>
|
||||
) : (
|
||||
<Text>in {dayjs(token.expires).fromNow(true)}</Text>
|
||||
<Text>in {dayjs(invite.expires).fromNow(true)}</Text>
|
||||
)}
|
||||
</td>
|
||||
<td className={classes.tableCell}>
|
||||
<ActionIcon
|
||||
onClick={() => {
|
||||
modals.openContextModal({
|
||||
modal: 'deleteRegistrationTokenModal',
|
||||
title: <Text weight="bold">Delete registration token</Text>,
|
||||
modal: 'deleteInviteModal',
|
||||
title: <Text weight="bold">Delete invite</Text>,
|
||||
innerProps: {
|
||||
tokenId: token.id,
|
||||
tokenId: invite.id,
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -103,7 +107,7 @@ const ManageUserInvitesPage = () => {
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
{data.registrationTokens.length === 0 && (
|
||||
{data.invites.length === 0 && (
|
||||
<tr>
|
||||
<td colSpan={3}>
|
||||
<Center p="md">
|
||||
@@ -137,8 +141,8 @@ const ManageUserInvitesPage = () => {
|
||||
};
|
||||
|
||||
const useStyles = createStyles(() => ({
|
||||
tableIdCell: {
|
||||
width: '100%',
|
||||
tableGrowCell: {
|
||||
width: '50%',
|
||||
},
|
||||
tableCell: {
|
||||
whiteSpace: 'nowrap',
|
||||
|
||||
@@ -14,7 +14,7 @@ import { useI18nZodResolver } from '~/utils/i18n-zod-resolver';
|
||||
import { updateSettingsValidationSchema } from '~/validations/user';
|
||||
|
||||
const PreferencesPage = ({ locale }: InferGetServerSidePropsType<typeof getServerSideProps>) => {
|
||||
const { data } = api.user.getWithSettings.useQuery();
|
||||
const { data } = api.user.withSettings.useQuery();
|
||||
|
||||
return (
|
||||
<ManageLayout>
|
||||
@@ -34,7 +34,7 @@ export const [FormProvider, useFormContext, useForm] =
|
||||
const SettingsComponent = ({
|
||||
settings,
|
||||
}: {
|
||||
settings: RouterOutputs['user']['getWithSettings']['settings'];
|
||||
settings: RouterOutputs['user']['withSettings']['settings'];
|
||||
}) => {
|
||||
const languagesData = languages.map((language) => ({
|
||||
image: 'https://img.icons8.com/clouds/256/000000/futurama-bender.png',
|
||||
|
||||
Reference in New Issue
Block a user