remove user.lastActiveTimestamp

This commit is contained in:
vincanger 2025-02-14 14:48:24 +01:00
parent 6c9d54e526
commit c6152345a8
6 changed files with 4 additions and 54 deletions

View File

@ -140,11 +140,6 @@ query getPaginatedUsers {
entities: [User]
}
action updateCurrentUserLastActiveTimestamp {
fn: import { updateCurrentUserLastActiveTimestamp } from "@src/user/operations",
entities: [User]
}
action updateIsUserAdminById {
fn: import { updateIsUserAdminById } from "@src/user/operations",
entities: [User]

View File

@ -13,7 +13,6 @@ model User {
email String? @unique
username String? @unique
lastActiveTimestamp DateTime @default(now())
isAdmin Boolean @default(false)
paymentProcessorUserId String? @unique

View File

@ -172,13 +172,10 @@ const UsersTable = () => {
</div>
</div>
<div className='grid grid-cols-12 border-t-4 border-stroke py-4.5 px-4 dark:border-strokedark md:px-6 '>
<div className='grid grid-cols-9 border-t-4 border-stroke py-4.5 px-4 dark:border-strokedark md:px-6 '>
<div className='col-span-3 flex items-center'>
<p className='font-medium'>Email / Username</p>
</div>
<div className='col-span-3 hidden items-center sm:flex'>
<p className='font-medium'>Last Active</p>
</div>
<div className='col-span-2 flex items-center'>
<p className='font-medium'>Subscription Status</p>
</div>
@ -202,7 +199,7 @@ const UsersTable = () => {
data.users.map((user) => (
<div
key={user.id}
className='grid grid-cols-12 gap-4 border-t border-stroke py-4.5 px-4 dark:border-strokedark md:px-6 '
className='grid grid-cols-9 gap-4 border-t border-stroke py-4.5 px-4 dark:border-strokedark md:px-6 '
>
<div className='col-span-3 flex items-center'>
<div className='flex flex-col gap-1 '>
@ -210,14 +207,6 @@ const UsersTable = () => {
<p className='text-sm text-black dark:text-white'>{user.username}</p>
</div>
</div>
<div className='col-span-3 hidden items-center sm:flex'>
<p className='text-sm text-black dark:text-white'>
{user.lastActiveTimestamp.toLocaleDateString() +
' ' +
user.lastActiveTimestamp.toLocaleTimeString()}
</p>
</div>
<div className='col-span-2 flex items-center'>
<p className='text-sm text-black dark:text-white'>{user.subscriptionStatus}</p>
</div>

View File

@ -8,7 +8,6 @@ import { routes } from 'wasp/client/router';
import { Outlet, useLocation } from 'react-router-dom';
import { useAuth } from 'wasp/client/auth';
import { useIsLandingPage } from './hooks/useIsLandingPage';
import { updateCurrentUserLastActiveTimestamp } from 'wasp/client/operations';
/**
* use this component to wrap all child components
@ -28,16 +27,6 @@ export default function App() {
return location.pathname.startsWith('/admin');
}, [location]);
useEffect(() => {
if (user) {
const lastSeenAt = new Date(user.lastActiveTimestamp);
const today = new Date();
if (today.getTime() - lastSeenAt.getTime() > 5 * 60 * 1000) {
updateCurrentUserLastActiveTimestamp();
}
}
}, [user]);
useEffect(() => {
if (location.hash) {
const id = location.hash.replace('#', '');

View File

@ -26,21 +26,20 @@ function generateMockUserData(): MockUserData {
const subscriptionStatus = faker.helpers.arrayElement<SubscriptionStatus | null>(['active', 'cancel_at_period_end', 'past_due', 'deleted', null]);
const now = new Date();
const createdAt = faker.date.past({ refDate: now });
const lastActiveTimestamp = faker.date.between({ from: createdAt, to: now });
const timePaid = faker.date.between({ from: createdAt, to: now });
const credits = subscriptionStatus ? 0 : faker.number.int({ min: 0, max: 10 });
const hasUserPaidOnStripe = !!subscriptionStatus || credits > 3
return {
email: faker.internet.email({ firstName, lastName }),
username: faker.internet.userName({ firstName, lastName }),
createdAt,
lastActiveTimestamp,
isAdmin: false,
sendNewsletter: false,
credits,
subscriptionStatus,
lemonSqueezyCustomerPortalUrl: null,
paymentProcessorUserId: hasUserPaidOnStripe ? `cus_test_${faker.string.uuid()}` : null,
datePaid: hasUserPaidOnStripe ? faker.date.between({ from: createdAt, to: lastActiveTimestamp }) : null,
datePaid: hasUserPaidOnStripe ? faker.date.between({ from: createdAt, to: timePaid }) : null,
subscriptionPlan: subscriptionStatus ? faker.helpers.arrayElement(getSubscriptionPaymentPlanIds()) : null,
};
}

View File

@ -1,5 +1,4 @@
import {
type UpdateCurrentUserLastActiveTimestamp,
type UpdateIsUserAdminById,
type GetPaginatedUsers,
} from 'wasp/server/operations';
@ -31,25 +30,6 @@ export const updateIsUserAdminById: UpdateIsUserAdminById<{ id: string; data: Pi
return updatedUser;
};
export const updateCurrentUserLastActiveTimestamp: UpdateCurrentUserLastActiveTimestamp<void, Pick<User, 'id' | 'lastActiveTimestamp'>> = async (_args, context) => {
if (!context.user) {
throw new HttpError(401);
}
return context.entities.User.update({
where: {
id: context.user.id,
},
data: {
lastActiveTimestamp: new Date(),
},
select: {
id: true,
lastActiveTimestamp: true,
},
});
};
type GetPaginatedUsersInput = {
skip: number;
cursor?: number | undefined;
@ -107,7 +87,6 @@ export const getPaginatedUsers: GetPaginatedUsers<GetPaginatedUsersInput, GetPag
email: true,
username: true,
isAdmin: true,
lastActiveTimestamp: true,
subscriptionStatus: true,
paymentProcessorUserId: true,
},