read content notification on click

This commit is contained in:
isUnknown 2025-01-15 15:36:43 +01:00
parent 1fae3dd414
commit 495e1c024e
7 changed files with 25 additions and 16 deletions

View file

@ -9,7 +9,6 @@ return [
$page = page($data->briefUri);
$project = $page->parent();
$dialogUri = $data->dialogUri ? $data->dialogUri : null;
try {
$newPage = $page->update([
@ -22,8 +21,6 @@ return [
$notification = [
'location' => [
'page' => $page,
'project' => $project,
'dialogUri' => (string) $dialogUri,
],
'date' => $dateTime->format('Y-m-d\TH:i:sP'),
'text' => "Nouveau brief",
@ -32,7 +29,7 @@ return [
'type' => 'content'
];
kirby()->user()->sendNotification($project, $notification);
$project->createNotification($notification);
return [
"success" => "'" . $project->title()->value() . "' brief validated."

View file

@ -147,7 +147,10 @@ function handleClick() {
async function read() {
if (getStatus.value !== "unread") return;
try {
const newNotification = await api.readNotification(comment, page.value.uri);
const newNotification = await api.readNotification(
comment.id,
page.value.uri
);
userStore.readNotification(comment.id, route.params.id);
} catch (error) {
console.log("Erreur lors de la lecture de la notification : ", error);

View file

@ -2,10 +2,7 @@
<article
class="notification | bg-white rounded-lg | p-16 | flow"
data-type="content"
@click="
read(notification);
router.push(notification.location.page.uri);
"
@click="readNotification()"
title="Aller au contenu"
>
<header>
@ -16,7 +13,7 @@
>Contenu</strong
>
<span class="notification__client | text-grey-700">{{
notification.location.project.title
notification.project.title
}}</span>
<time
datetime=""
@ -37,8 +34,17 @@
<script setup>
import { useRouter } from "vue-router";
import { useNotificationsStore } from "../../stores/notifications";
import { useUserStore } from "../../stores/user";
import { useApiStore } from "../../stores/api";
const router = useRouter();
const { notification } = defineProps({ notification: Object });
const { formatDate, read } = useNotificationsStore();
const { formatDate } = useNotificationsStore();
const userStore = useUserStore();
const api = useApiStore();
function readNotification() {
api.readNotification(notification.id, notification.project.uri);
userStore.readNotification(notification.id, notification.project.slug);
}
</script>

View file

@ -17,7 +17,7 @@
}}</strong
>
<span class="notification__client | text-grey-700">{{
notification.location.project.title
notification.project.title
}}</span>
<time
datetime=""

View file

@ -149,12 +149,12 @@ export const useApiStore = defineStore("api", () => {
* @param {string} projectId UUID or URI
* @returns status with message if error
*/
async function readNotification(comment, projectId) {
async function readNotification(notificationId, projectId) {
const headers = {
method: "POST",
body: JSON.stringify({
projectId,
notificationId: comment.id,
notificationId,
}),
};
try {

View file

@ -13,7 +13,10 @@
class="btn | ml-auto"
@click="validate"
v-if="page.content.isvalidated != 'true'"
:disabled="page.files.length === 0"
:disabled="page.moodboard.length === 0"
:title="
page.moodboard.length === 0 ? 'Ajoutez au moins une image' : undefined
"
>
Valider et envoyer le brief
</button>

View file

@ -129,7 +129,7 @@ function getHref(notification) {
const isDocumentBrief =
notification.location.page.template === "client-brief" &&
notification.location?.file.type === "document";
notification.location?.file?.type === "document";
if (isDocumentBrief) {
return notification.project.uri + "?dialog=client-brief&comments=true";