--- import { Icon } from 'astro-icon/components' import { actions, isInputError } from 'astro:actions' import BadgeSmall from '../../../components/BadgeSmall.astro' import Button from '../../../components/Button.astro' import InputCardGroup from '../../../components/InputCardGroup.astro' import InputImageFile from '../../../components/InputImageFile.astro' import InputSelect from '../../../components/InputSelect.astro' import InputSubmitButton from '../../../components/InputSubmitButton.astro' import InputText from '../../../components/InputText.astro' import InputTextArea from '../../../components/InputTextArea.astro' import MyPicture from '../../../components/MyPicture.astro' import TimeFormatted from '../../../components/TimeFormatted.astro' import { getServiceUserRoleInfo, serviceUserRoles } from '../../../constants/serviceUserRoles' import BaseLayout from '../../../layouts/BaseLayout.astro' import { prisma } from '../../../lib/prisma' const { username } = Astro.params if (!username) return Astro.rewrite('/404') const updateResult = Astro.getActionResult(actions.admin.user.update) Astro.locals.banners.addIfSuccess(updateResult, 'User updated successfully') if (updateResult && !updateResult.error && username !== updateResult.data.updatedUser.name) { return Astro.redirect(`/admin/users/${updateResult.data.updatedUser.name}`) } const updateInputErrors = isInputError(updateResult?.error) ? updateResult.error.fields : {} const addAffiliationResult = Astro.getActionResult(actions.admin.user.serviceAffiliations.add) Astro.locals.banners.addIfSuccess(addAffiliationResult, 'Service affiliation added successfully') const removeAffiliationResult = Astro.getActionResult(actions.admin.user.serviceAffiliations.remove) Astro.locals.banners.addIfSuccess(removeAffiliationResult, 'Service affiliation removed successfully') const addKarmaTransactionResult = Astro.getActionResult(actions.admin.user.karmaTransactions.add) Astro.locals.banners.addIfSuccess(addKarmaTransactionResult, 'Karma transaction added successfully') const [user, allServices] = await Astro.locals.banners.tryMany([ [ 'Failed to load user profile', async () => { if (!username) return null return await prisma.user.findUnique({ where: { name: username }, select: { id: true, name: true, displayName: true, picture: true, link: true, admin: true, verified: true, verifier: true, spammer: true, verifiedLink: true, internalNotes: { select: { id: true, content: true, createdAt: true, addedByUser: { select: { id: true, name: true, displayName: true, picture: true, }, }, }, orderBy: { createdAt: 'desc', }, }, serviceAffiliations: { select: { id: true, role: true, createdAt: true, service: { select: { id: true, name: true, slug: true, }, }, }, orderBy: { createdAt: 'desc', }, }, }, }) }, null, ], [ 'Failed to load services', async () => { return await prisma.service.findMany({ select: { id: true, name: true, }, orderBy: { name: 'asc', }, }) }, [], ], ]) if (!user) return Astro.rewrite('/404') ---
{ !!user.picture && ( ) }

{user.displayName ? `${user.displayName} (${user.name})` : user.name}

{user.admin && } {user.verified && } {user.verifier && } {user.spammer && }

Edit profile

v !== null)} required cardSize="sm" iconSize="sm" multiple error={updateInputErrors.type} />

Internal Notes

{ user.internalNotes.length === 0 ? (

No internal notes yet.

) : (
{user.internalNotes.map((note) => (
{!!note.addedByUser?.picture && ( )} {/* eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing */} {note.addedByUser ? note.addedByUser.displayName || note.addedByUser.name : 'System'}

))}
) }

Add Note

Service Affiliations

{ user.serviceAffiliations.length === 0 ? (

No service affiliations yet.

) : (
{user.serviceAffiliations.map((affiliation) => { const roleInfo = getServiceUserRoleInfo(affiliation.role) return ( ) })}
) }

Add Affiliation

({ label: service.name, value: service.id.toString(), }))} selectProps={{ required: true }} /> ({ label: role.label, value: role.value, icon: role.icon, }))} required cardSize="sm" iconSize="sm" />

Grant/Remove Karma