chore: implemented feedback

This commit is contained in:
Catalin Pit
2023-12-14 11:05:39 +02:00
parent e79d385534
commit 19736ce60b
3 changed files with 22 additions and 8 deletions

View File

@ -63,17 +63,29 @@ export const ApiTokenForm = ({ className }: ApiTokenFormProps) => {
*/
const onDelete = (tokenId: number) => {
if (tokenId === newlyCreatedToken.id) {
setShowNewToken((prev) => !prev);
setShowNewToken(false);
}
};
const copyToken = (token: string) => {
void copy(token).then(() => {
const copyToken = async (token: string) => {
try {
const copied = await copy(token);
if (!copied) {
throw new Error('Unable to copy the token');
}
toast({
title: 'Token copied to clipboard',
description: 'The token was copied to your clipboard.',
});
});
} catch (error) {
toast({
title: 'Unable to copy token',
description: 'We were unable to copy the token to your clipboard. Please try again.',
variant: 'destructive',
});
}
};
const onSubmit = async ({ tokenName }: TCreateTokenMutationSchema) => {
@ -146,7 +158,7 @@ export const ApiTokenForm = ({ className }: ApiTokenFormProps) => {
<p className="mb-4 text-sm">
Expires:{' '}
{token.expires
? DateTime.fromJSDate(token.createdAt).toLocaleString(DateTime.DATETIME_FULL)
? DateTime.fromJSDate(token.expires).toLocaleString(DateTime.DATETIME_FULL)
: 'N/A'}
</p>
<DeleteTokenDialog
@ -169,7 +181,7 @@ export const ApiTokenForm = ({ className }: ApiTokenFormProps) => {
<Button
variant="outline"
className="mt-4"
onClick={() => copyToken(newlyCreatedToken.token)}
onClick={() => void copyToken(newlyCreatedToken.token)}
>
Copy token
</Button>

View File

@ -15,13 +15,13 @@ export const checkUserFromToken = async ({ token }: { token: string }) => {
});
if (!user) {
throw new Error('Token not found');
throw new Error('Invalid token');
}
const tokenObject = user.ApiToken.find((apiToken) => apiToken.token === token);
if (!tokenObject || new Date(tokenObject.expires) < new Date()) {
throw new Error('The API token has expired');
throw new Error('Expired token');
}
return user;

View File

@ -18,6 +18,8 @@ export const fieldRouter = router({
try {
const { documentId, fields } = input;
console.log('fields', fields);
return await setFieldsForDocument({
documentId,
userId: ctx.user.id,