Skip to content

Commit

Permalink
Fix broken dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
7dev7urandom committed Feb 1, 2025
1 parent 938d6e8 commit a5364b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const lockSchema = v.object({
active: v.boolean()
});

const userSchema = v.object({
const searchFilterSchema = v.object({
page: paginateSchema,
search: v.string(),
organizationId: v.nullable(idSchema)
Expand Down Expand Up @@ -57,28 +57,28 @@ function select(orgIds?: number[]) {
function adminOrDefaultWhere(isSuper: boolean, orgIds: number[]) {
return isSuper
? {
// Get all users that are locked or are a member of at least one organization
// (Users that are not in an organization and are not locked are not interesting
// because they can't login and behave essentially as locked users or as users
// who have never logged in before)
OR: [
{
OrganizationMemberships: {
some: {}
// Get all users that are locked or are a member of at least one organization
// (Users that are not in an organization and are not locked are not interesting
// because they can't login and behave essentially as locked users or as users
// who have never logged in before)
OR: [
{
OrganizationMemberships: {
some: {}
}
},
{
IsLocked: true
}
},
{
IsLocked: true
}
]
}
]
}
: {
OrganizationMemberships: {
some: {
OrganizationId: { in: orgIds }
OrganizationMemberships: {
some: {
OrganizationId: { in: orgIds }
}
}
}
};
};
}

export const load = (async (event) => {
Expand All @@ -92,13 +92,13 @@ export const load = (async (event) => {
where: isSuper
? undefined
: {
UserRoles: {
some: {
RoleId: RoleId.OrgAdmin,
UserId: userId
UserRoles: {
some: {
RoleId: RoleId.OrgAdmin,
UserId: userId
}
}
}
},
},
select: {
Id: true,
Name: true,
Expand Down Expand Up @@ -153,7 +153,7 @@ export const load = (async (event) => {
size: 50
}
},
valibot(userSchema)
valibot(searchFilterSchema)
)
};
}) satisfies PageServerLoad;
Expand All @@ -178,7 +178,7 @@ export const actions: Actions = {
async page(event) {
const session = await event.locals.auth();
if (!session) return error(403);
const form = await superValidate(event, valibot(userSchema));
const form = await superValidate(event, valibot(searchFilterSchema));
if (!form.valid) return { form, ok: false };

const isSuper = isSuperAdmin(session.user.roles);
Expand All @@ -190,13 +190,13 @@ export const actions: Actions = {
: isSuper
? undefined
: {
UserRoles: {
some: {
RoleId: RoleId.OrgAdmin,
UserId: session.user.userId
UserRoles: {
some: {
RoleId: RoleId.OrgAdmin,
UserId: session.user.userId
}
}
}
},
},
select: {
Id: true,
Name: true,
Expand All @@ -212,19 +212,19 @@ export const actions: Actions = {
{
OR: form.data.search
? [
{
Name: {
contains: form.data.search,
mode: 'insensitive'
{
Name: {
contains: form.data.search,
mode: 'insensitive'
}
},
{
Email: {
contains: form.data.search,
mode: 'insensitive'
}
}
},
{
Email: {
contains: form.data.search,
mode: 'insensitive'
}
}
]
]
: undefined
}
]
Expand All @@ -241,7 +241,6 @@ export const actions: Actions = {
skip: form.data.page.page * form.data.page.size,
take: form.data.page.size
});

return {
form,
ok: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@
{#if data.organizationCount > 1}
<label class="flex flex-wrap items-center gap-x-2 w-full max-w-xs md:w-auto md:max-w-none">
<span class="label-text">{m.users_organization_filter()}:</span>
<select class="select select-bordered grow" name="org" bind:value={$form.organizationId}>
<select class="select select-bordered grow" bind:value={$form.organizationId}>
<option value={null}>{m.org_allOrganizations()}</option>
{#each Object.entries(data.organizations) as [Id, Name]}
<option value={Id}>{Name}</option>
<option value={parseInt(Id)}>{Name}</option>
{/each}
</select>
</label>
Expand Down

0 comments on commit a5364b7

Please sign in to comment.