mirror of
https://github.com/wasp-lang/open-saas.git
synced 2025-03-29 11:12:19 +01:00
Update template to latest changes. Fixes user update bug
This commit is contained in:
parent
73c623e011
commit
3d3796d81f
@ -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<string | null> | 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,
|
||||
|
@ -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
|
||||
|
@ -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<User>; updateUserById?: any }) => {
|
||||
const SwitcherOne = ({ user, updateIsUserAdminById }: { user?: Partial<User>; updateIsUserAdminById?: any }) => {
|
||||
const [enabled, setEnabled] = useState<boolean>(user?.isAdmin || false);
|
||||
|
||||
return (
|
||||
@ -15,7 +15,7 @@ const SwitcherOne = ({ user, updateUserById }: { user?: Partial<User>; updateUse
|
||||
className='sr-only'
|
||||
onChange={() => {
|
||||
setEnabled(!enabled);
|
||||
updateUserById && updateUserById({ id: user?.id, data: { isAdmin: !enabled } });
|
||||
updateIsUserAdminById && updateIsUserAdminById({ id: user?.id, data: { isAdmin: !enabled } });
|
||||
}}
|
||||
/>
|
||||
<div className='reblock h-8 w-14 rounded-full bg-meta-9 dark:bg-[#5A616B]'></div>
|
||||
|
@ -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 = () => {
|
||||
</div>
|
||||
<div className='col-span-1 flex items-center'>
|
||||
<div className='text-sm text-black dark:text-white'>
|
||||
<SwitcherOne user={user} updateUserById={updateUserById} />
|
||||
<SwitcherOne user={user} updateIsUserAdminById={updateIsUserAdminById} />
|
||||
</div>
|
||||
</div>
|
||||
<div className='col-span-1 flex items-center'>
|
||||
|
@ -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]);
|
||||
|
@ -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> }, User> = async (
|
||||
export const updateIsUserAdminById: UpdateIsUserAdminById<{ id: string; data: Pick<User, 'isAdmin'> }, User> = async (
|
||||
{ id, data },
|
||||
context
|
||||
) => {
|
||||
@ -23,13 +23,15 @@ export const updateUserById: UpdateUserById<{ id: string; data: Partial<User> },
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
data,
|
||||
data: {
|
||||
isAdmin: data.isAdmin,
|
||||
},
|
||||
});
|
||||
|
||||
return updatedUser;
|
||||
};
|
||||
|
||||
export const updateCurrentUser: UpdateCurrentUser<Partial<User>, User> = async (user, context) => {
|
||||
export const updateCurrentUserLastActiveTimestamp: UpdateCurrentUserLastActiveTimestamp<Pick<User, 'lastActiveTimestamp'>, User> = async ({ lastActiveTimestamp }, context) => {
|
||||
if (!context.user) {
|
||||
throw new HttpError(401);
|
||||
}
|
||||
@ -38,7 +40,7 @@ export const updateCurrentUser: UpdateCurrentUser<Partial<User>, User> = async (
|
||||
where: {
|
||||
id: context.user.id,
|
||||
},
|
||||
data: user,
|
||||
data: {lastActiveTimestamp},
|
||||
});
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user