diff --git a/opensaas-sh/app_diff/src/user/operations.ts.diff b/opensaas-sh/app_diff/src/user/operations.ts.diff index df055c8..7b7ff0c 100644 --- a/opensaas-sh/app_diff/src/user/operations.ts.diff +++ b/opensaas-sh/app_diff/src/user/operations.ts.diff @@ -1,16 +1,6 @@ --- template/app/src/user/operations.ts +++ opensaas-sh/app/src/user/operations.ts -@@ -1,8 +1,4 @@ --import { -- type UpdateCurrentUser, -- type UpdateUserById, -- type GetPaginatedUsers, --} from 'wasp/server/operations'; -+import { type UpdateCurrentUser, type UpdateUserById, type GetPaginatedUsers } from 'wasp/server/operations'; - import { type User } from 'wasp/entities'; - import { HttpError } from 'wasp/server'; - import { type SubscriptionStatus } from '../payment/plans'; -@@ -50,7 +46,10 @@ +@@ -52,7 +52,10 @@ subscriptionStatus?: SubscriptionStatus[]; }; type GetPaginatedUsersOutput = { @@ -22,7 +12,7 @@ totalPages: number; }; -@@ -63,8 +62,10 @@ +@@ -65,8 +68,10 @@ } const allSubscriptionStatusOptions = args.subscriptionStatus as Array | undefined; @@ -35,7 +25,7 @@ const queryResults = await context.entities.User.findMany({ skip: args.skip, -@@ -77,6 +78,7 @@ +@@ -79,6 +84,7 @@ mode: 'insensitive', }, isAdmin: args.isAdmin, @@ -43,7 +33,7 @@ }, { OR: [ -@@ -101,7 +103,7 @@ +@@ -103,7 +109,7 @@ isAdmin: true, lastActiveTimestamp: true, subscriptionStatus: true, @@ -52,7 +42,7 @@ }, orderBy: { id: 'desc', -@@ -117,6 +119,7 @@ +@@ -119,6 +125,7 @@ mode: 'insensitive', }, isAdmin: args.isAdmin, diff --git a/template/app/main.wasp b/template/app/main.wasp index aeb4037..84d3c4e 100644 --- a/template/app/main.wasp +++ b/template/app/main.wasp @@ -140,13 +140,13 @@ query getPaginatedUsers { entities: [User] } -action updateCurrentUser { - fn: import { updateCurrentUser } from "@src/user/operations", +action updateCurrentUserLastActiveTimestamp { + fn: import { updateCurrentUserLastActiveTimestamp } from "@src/user/operations", entities: [User] } -action updateUserById { - fn: import { updateUserById } from "@src/user/operations", +action updateIsUserAdminById { + fn: import { updateIsUserAdminById } from "@src/user/operations", entities: [User] } //#endregion diff --git a/template/app/src/admin/dashboards/users/SwitcherOne.tsx b/template/app/src/admin/dashboards/users/SwitcherOne.tsx index 6721194..084cabe 100644 --- a/template/app/src/admin/dashboards/users/SwitcherOne.tsx +++ b/template/app/src/admin/dashboards/users/SwitcherOne.tsx @@ -2,7 +2,7 @@ import { type User } from 'wasp/entities'; import { useState } from 'react'; import { cn } from '../../../client/cn'; -const SwitcherOne = ({ user, updateUserById }: { user?: Partial; updateUserById?: any }) => { +const SwitcherOne = ({ user, updateIsUserAdminById }: { user?: Partial; updateIsUserAdminById?: any }) => { const [enabled, setEnabled] = useState(user?.isAdmin || false); return ( @@ -15,7 +15,7 @@ const SwitcherOne = ({ user, updateUserById }: { user?: Partial; updateUse className='sr-only' onChange={() => { setEnabled(!enabled); - updateUserById && updateUserById({ id: user?.id, data: { isAdmin: !enabled } }); + updateIsUserAdminById && updateIsUserAdminById({ id: user?.id, data: { isAdmin: !enabled } }); }} />
diff --git a/template/app/src/admin/dashboards/users/UsersTable.tsx b/template/app/src/admin/dashboards/users/UsersTable.tsx index 2043149..6e1dccd 100644 --- a/template/app/src/admin/dashboards/users/UsersTable.tsx +++ b/template/app/src/admin/dashboards/users/UsersTable.tsx @@ -1,5 +1,5 @@ import { type SubscriptionStatus } from '../../../payment/plans'; -import { updateUserById, useQuery, getPaginatedUsers } from 'wasp/client/operations'; +import { updateIsUserAdminById, useQuery, getPaginatedUsers } from 'wasp/client/operations'; import { useState, useEffect } from 'react'; import SwitcherOne from './SwitcherOne'; import LoadingSpinner from '../../layout/LoadingSpinner'; @@ -226,7 +226,7 @@ const UsersTable = () => {
- +
diff --git a/template/app/src/client/App.tsx b/template/app/src/client/App.tsx index ead2651..9957f27 100644 --- a/template/app/src/client/App.tsx +++ b/template/app/src/client/App.tsx @@ -8,7 +8,7 @@ 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 { updateCurrentUser } from 'wasp/client/operations'; +import { updateCurrentUserLastActiveTimestamp } from 'wasp/client/operations'; /** * use this component to wrap all child components @@ -21,7 +21,9 @@ export default function App() { const navigationItems = isLandingPage ? landingPageNavigationItems : appNavigationItems; const shouldDisplayAppNavBar = useMemo(() => { - return location.pathname !== routes.LoginRoute.build() && location.pathname !== routes.SignupRoute.build(); + return ( + location.pathname !== routes.LoginRoute.build() && location.pathname !== routes.SignupRoute.build() + ); }, [location]); const isAdminDashboard = useMemo(() => { @@ -33,7 +35,7 @@ export default function App() { const lastSeenAt = new Date(user.lastActiveTimestamp); const today = new Date(); if (today.getTime() - lastSeenAt.getTime() > 5 * 60 * 1000) { - updateCurrentUser({ lastActiveTimestamp: today }); + updateCurrentUserLastActiveTimestamp({ lastActiveTimestamp: today }); } } }, [user]); diff --git a/template/app/src/user/operations.ts b/template/app/src/user/operations.ts index 441de67..d0bdb7f 100644 --- a/template/app/src/user/operations.ts +++ b/template/app/src/user/operations.ts @@ -1,13 +1,13 @@ import { - type UpdateCurrentUser, - type UpdateUserById, + type UpdateCurrentUserLastActiveTimestamp, + type UpdateIsUserAdminById, type GetPaginatedUsers, } from 'wasp/server/operations'; import { type User } from 'wasp/entities'; import { HttpError } from 'wasp/server'; import { type SubscriptionStatus } from '../payment/plans'; -export const updateUserById: UpdateUserById<{ id: string; data: Partial }, User> = async ( +export const updateIsUserAdminById: UpdateIsUserAdminById<{ id: string; data: Pick }, User> = async ( { id, data }, context ) => { @@ -23,13 +23,15 @@ export const updateUserById: UpdateUserById<{ id: string; data: Partial }, where: { id, }, - data, + data: { + isAdmin: data.isAdmin, + }, }); return updatedUser; }; -export const updateCurrentUser: UpdateCurrentUser, User> = async (user, context) => { +export const updateCurrentUserLastActiveTimestamp: UpdateCurrentUserLastActiveTimestamp, User> = async ({ lastActiveTimestamp }, context) => { if (!context.user) { throw new HttpError(401); } @@ -38,7 +40,7 @@ export const updateCurrentUser: UpdateCurrentUser, User> = async ( where: { id: context.user.id, }, - data: user, + data: {lastActiveTimestamp}, }); };