Skip to content

Commit

Permalink
Added real-time notification data with Prisma and React Admin
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianLeChat committed Feb 6, 2024
1 parent 528c9aa commit 96b4382
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
41 changes: 41 additions & 0 deletions app/[locale]/components/admin/notification.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Composant de gestion des notifications.
//
import { List,
Datagrid,
DateField,
NumberField,
ReferenceField } from "react-admin";

// Affichage des notification.
export function NotificationList()
{
return (
<List>
<Datagrid bulkActionButtons={false}>
{/* Numéro de la notification */}
<NumberField source="id" label="Numéro" />

{/* Relation avec l'utilisateur */}
<ReferenceField
label="Utilisateur"
source="userId"
reference="user"
/>

{/* Identifiant du titre de la notification */}
<NumberField label="Titre" source="title" />

{/* Identifiant de la description de la notification */}
<NumberField label="Description" source="description" />

{/* Date de création de la notification */}
<DateField
label="Date de création"
source="createdAt"
showTime
/>
</Datagrid>
</List>
);
}
10 changes: 10 additions & 0 deletions app/[locale]/components/administration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Bug,
Save,
User,
Share2,
BellRing,
KeyRound,
FileArchive,
SquareStack,
Expand Down Expand Up @@ -39,6 +40,7 @@ import { TokenList } from "./admin/verification-token";
import { VersionList } from "./admin/version";
import { AccountList } from "./admin/account";
import { SessionList } from "./admin/session";
import { NotificationList } from "./admin/notification";
import { UserCreate, UserEdit, UserList } from "./admin/user";

// Basculement entre les traductions.
Expand Down Expand Up @@ -171,6 +173,14 @@ export default function Administration()
options={{ label: "Comptes OAuth" }}
/>

{/* Notifications */}
<Resource
icon={BellRing}
name="notification"
list={NotificationList}
options={{ label: "Notifications" }}
/>

{/* Fichiers téléversés */}
<Resource
icon={FileArchive}
Expand Down
4 changes: 2 additions & 2 deletions app/[locale]/settings/notifications/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function updateNotifications(

// On met à jour après le niveau de notifications de l'utilisateur dans la
// base de données.
const notifications =
const notification =
result.data.push && result.data.level !== "off"
? `${ result.data.level }+mail`
: result.data.level;
Expand All @@ -57,7 +57,7 @@ export async function updateNotifications(
email: session.user.email as string
},
data: {
notifications
notification
}
} );

Expand Down
12 changes: 11 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ model Version {
createdAt DateTime @default(now())
}

model Notification {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
title Int
message Int
createdAt DateTime @default(now())
}

model Preference {
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String @id
Expand All @@ -91,7 +100,7 @@ model User {
name String?
email String @unique
password String?
notifications String? @default("necessary")
notification String? @default("necessary")
emailVerified DateTime?
image String?
role String @default("user")
Expand All @@ -101,6 +110,7 @@ model User {
files File[]
preferences Preference[]
shares Share[]
notifications Notification[]
}

model VerificationToken {
Expand Down

0 comments on commit 96b4382

Please sign in to comment.