feat: enhance chat sidebar with admin indicator and simplify user retrieval logic
This commit is contained in:
parent
d6c0e67bfd
commit
b7e1e964c3
3 changed files with 18 additions and 22 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { Check, CheckCheck, Search, SquarePen } from "lucide-react";
|
import { Check, CheckCheck, Crown, Search, SquarePen } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
|
|
@ -159,15 +159,21 @@ export const ChatSidebar = ({
|
||||||
)}
|
)}
|
||||||
onClick={() => handleChatSelection(chat.chatid)}
|
onClick={() => handleChatSelection(chat.chatid)}
|
||||||
>
|
>
|
||||||
<UserAvatar
|
{chat.id === userId ? (
|
||||||
className="size-10"
|
<div className="flex size-10 items-center justify-center rounded-full bg-yellow-500 text-white text-xs">
|
||||||
userId={chat.id}
|
<Crown className="size-4" />
|
||||||
username={chat.username}
|
</div>
|
||||||
/>
|
) : (
|
||||||
|
<UserAvatar
|
||||||
|
className="size-10"
|
||||||
|
userId={chat.id}
|
||||||
|
username={chat.username}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{isDesktop && (
|
{isDesktop && (
|
||||||
<div className="flex h-full max-w-28 flex-col text-left align-top">
|
<div className="flex h-full max-w-28 flex-col text-left align-top">
|
||||||
<span>{chat.username}</span>
|
<span>{chat.id === userId ? "Admin Infoalloggi" : chat.username}</span>
|
||||||
<div className="flex flex-wrap gap-2">
|
<div className="flex flex-wrap gap-2">
|
||||||
{chat.etichette.map((etichetta) => (
|
{chat.etichette.map((etichetta) => (
|
||||||
<Etichetta
|
<Etichetta
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ export const usersRouter = createTRPCRouter({
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
return await getUserHandler({ db, id: input.id });
|
return await getUserHandler(input.id);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getUsers: adminProcedure.query(async () => {
|
getUsers: adminProcedure.query(async () => {
|
||||||
|
|
@ -96,7 +96,7 @@ export const usersRouter = createTRPCRouter({
|
||||||
return await editAnagraficaHandler({ ...input });
|
return await editAnagraficaHandler({ ...input });
|
||||||
}),
|
}),
|
||||||
getActiveUsersWithoutChat: adminProcedure.query(async () => {
|
getActiveUsersWithoutChat: adminProcedure.query(async () => {
|
||||||
return await getActiveUserWithoutChatHandler({ db });
|
return await getActiveUserWithoutChatHandler();
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getUsersWChatInfo: adminProcedure.query(async () => {
|
getUsersWChatInfo: adminProcedure.query(async () => {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import type { Etichette } from "~/schemas/public/Etichette";
|
||||||
import type { Users, UsersId, UsersUpdate } from "~/schemas/public/Users";
|
import type { Users, UsersId, UsersUpdate } from "~/schemas/public/Users";
|
||||||
import type { UsersAnagraficaUpdate } from "~/schemas/public/UsersAnagrafica";
|
import type { UsersAnagraficaUpdate } from "~/schemas/public/UsersAnagrafica";
|
||||||
import { getComuni, getNazioni } from "~/server/controllers/catasto.controller";
|
import { getComuni, getNazioni } from "~/server/controllers/catasto.controller";
|
||||||
import { db, type Querier } from "~/server/db";
|
import { db } from "~/server/db";
|
||||||
import { startsWithVowel, titleCase } from "~/utils/utils";
|
import { startsWithVowel, titleCase } from "~/utils/utils";
|
||||||
|
|
||||||
export const editAccountHandler = async ({
|
export const editAccountHandler = async ({
|
||||||
|
|
@ -101,13 +101,7 @@ export const blockUserHandler = async (id: UsersId) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getUserHandler = async ({
|
export const getUserHandler = async (id: UsersId) => {
|
||||||
db,
|
|
||||||
id,
|
|
||||||
}: {
|
|
||||||
db: Querier;
|
|
||||||
id: UsersId;
|
|
||||||
}) => {
|
|
||||||
try {
|
try {
|
||||||
const user = await db
|
const user = await db
|
||||||
.selectFrom("users")
|
.selectFrom("users")
|
||||||
|
|
@ -134,11 +128,7 @@ export type NonNullableUser = {
|
||||||
username: NonNullable<string>;
|
username: NonNullable<string>;
|
||||||
nome: string | null;
|
nome: string | null;
|
||||||
};
|
};
|
||||||
export const getActiveUserWithoutChatHandler = async ({
|
export const getActiveUserWithoutChatHandler = async () => {
|
||||||
db,
|
|
||||||
}: {
|
|
||||||
db: Querier;
|
|
||||||
}) => {
|
|
||||||
try {
|
try {
|
||||||
const users = await db
|
const users = await db
|
||||||
.selectFrom("users")
|
.selectFrom("users")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue