better system messages, display name relocation
Some checks failed
linter / quality (push) Failing after 1m6s
tests / ci (8.3) (push) Failing after 54s
tests / ci (8.4) (push) Failing after 1m8s
tests / ci (8.5) (push) Failing after 1m13s

This commit is contained in:
Daan Meijer 2026-06-17 11:00:35 +02:00
parent 0fee3c1972
commit c6d482e3de
22 changed files with 689 additions and 204 deletions

View File

@ -56,7 +56,12 @@ class DynamicController extends Controller
'ledgers.media',
'participants' => fn($query) => $query->withPivot('display_name'),
'chat.messages.user',
'chat.messages.media'
'chat.messages.media',
'chat.messages.subject' => function ($morphTo) {
$morphTo->morphWith([
\App\Models\Mutation::class => ['ledger'],
]);
}
]);
$isOwner = $dynamic->participants()

View File

@ -116,7 +116,7 @@ class DynamicInvitationController extends Controller
// Log to Dynamic chat activity log!
$dynamic->chat->messages()->create([
'user_id' => null,
'content' => "{$request->user()->name} joined the Dynamic as a " . strtoupper($invitation->role),
'content' => "<user:{$request->user()->id}> joined the Dynamic as a " . strtoupper($invitation->role),
'subject_id' => $request->user()->id,
'subject_type' => \App\Models\User::class,
]);

View File

@ -74,7 +74,12 @@ class LedgerController extends Controller
'mutations.user',
'mutations.media',
'mutations.chat.messages.user',
'mutations.chat.messages.media'
'mutations.chat.messages.media',
'mutations.chat.messages.subject' => function ($morphTo) {
$morphTo->morphWith([
\App\Models\Mutation::class => ['ledger'],
]);
}
]);
$isOwner = $dynamic->participants()

View File

@ -67,30 +67,6 @@ class MutationController extends Controller
return $mutation;
});
// Log to Mutation and Dynamic chats
$user = $request->user();
$mutationMsg = $mutation->chat->messages()->create([
'user_id' => $user->id,
'content' => $status === 'approved'
? "System: Entry was created by {$user->name}."
: "System: Suggestion was created by {$user->name}.",
]);
broadcast(new \App\Events\MessageSent($mutationMsg));
if ($status === 'approved') {
$dynamicMsg = $dynamic->chat->messages()->create([
'user_id' => $user->id,
'content' => "System: {$user->name} added entry \"{$mutation->description}\" for " . ($mutation->amount >= 0 ? '+' : '') . "{$mutation->amount} points on \"{$ledger->name}\" ledger.",
]);
} else {
$dynamicMsg = $dynamic->chat->messages()->create([
'user_id' => $user->id,
'content' => "System: {$user->name} suggested \"{$mutation->description}\" for " . ($mutation->amount >= 0 ? '+' : '') . "{$mutation->amount} points on \"{$ledger->name}\" ledger.",
]);
}
broadcast(new \App\Events\MessageSent($dynamicMsg));
// Broadcast the real-time creation event!
broadcast(new \App\Events\MutationCreated($mutation));
@ -151,20 +127,26 @@ class MutationController extends Controller
$statusText = strtoupper($newStatus);
$mutationMsg = $mutation->chat->messages()->create([
'user_id' => $user->id,
'content' => "System: Suggestion was {$statusText} by {$user->name}.",
'user_id' => null,
'content' => "Suggestion was {$statusText} by <user:{$user->id}>.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
broadcast(new \App\Events\MessageSent($mutationMsg));
if ($newStatus === 'approved') {
$dynamicMsg = $dynamic->chat->messages()->create([
'user_id' => $user->id,
'content' => "System: {$user->name} APPROVED the suggestion \"{$mutation->description}\" for " . ($mutation->amount >= 0 ? '+' : '') . "{$mutation->amount} points on \"{$ledger->name}\" ledger.",
'user_id' => null,
'content' => "<user:{$user->id}> APPROVED the suggestion \"{$mutation->description}\" for " . ($mutation->amount >= 0 ? '+' : '') . "{$mutation->amount} points on \"{$ledger->name}\" ledger.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
} else {
$dynamicMsg = $dynamic->chat->messages()->create([
'user_id' => $user->id,
'content' => "System: {$user->name} REJECTED the suggestion \"{$mutation->description}\" on \"{$ledger->name}\" ledger.",
'user_id' => null,
'content' => "<user:{$user->id}> REJECTED the suggestion \"{$mutation->description}\" on \"{$ledger->name}\" ledger.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
}
broadcast(new \App\Events\MessageSent($dynamicMsg));

View File

@ -3,10 +3,40 @@
namespace App\Http\Controllers;
use App\Models\Dynamic;
use App\Models\User;
use Illuminate\Http\Request;
use Inertia\Inertia;
class ParticipantController extends Controller
{
public function show(Request $request, Dynamic $dynamic, User $user)
{
// Ensure both the authenticated user and the target user are in the dynamic
if (!$dynamic->participants()->where('user_id', $request->user()->id)->exists()) {
abort(403);
}
$participant = $dynamic->participants()->where('user_id', $user->id)->firstOrFail();
$mutations = $user->mutations()
->whereHas('ledger', fn($query) => $query->where('dynamic_id', $dynamic->id))
->with('ledger')
->latest('id')
->take(10)
->get();
return Inertia::render('Participants/Show', [
'dynamic' => $dynamic,
'participant' => [
'id' => $user->id,
'name' => $user->name,
'display_name' => $participant->pivot->display_name,
'role' => $participant->pivot->role,
],
'mutations' => $mutations,
]);
}
public function update(Request $request, Dynamic $dynamic)
{
$request->validate([

View File

@ -19,9 +19,14 @@ class ProfileController extends Controller
*/
public function edit(Request $request): Response
{
$dynamics = $request->user()->dynamics()
->withPivot('display_name')
->get();
return Inertia::render('settings/Profile', [
'mustVerifyEmail' => $request->user() instanceof MustVerifyEmail,
'status' => $request->session()->get('status'),
'dynamics' => $dynamics,
]);
}

View File

@ -46,6 +46,39 @@ class Mutation extends Model
{
static::created(function (Mutation $mutation) {
$mutation->chat()->create([]);
// Create system messages automatically!
$user = $mutation->user;
$ledger = $mutation->ledger;
$dynamic = $ledger->dynamic;
$status = $mutation->status;
$mutationMsg = $mutation->chat->messages()->create([
'user_id' => null,
'content' => $status === 'approved'
? "Entry was created by <user:{$user->id}>."
: "Suggestion was created by <user:{$user->id}>.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
broadcast(new \App\Events\MessageSent($mutationMsg));
if ($status === 'approved') {
$dynamicMsg = $dynamic->chat->messages()->create([
'user_id' => null,
'content' => "<user:{$user->id}> added entry \"{$mutation->description}\" for " . ($mutation->amount >= 0 ? '+' : '') . "{$mutation->amount} points on \"{$ledger->name}\" ledger.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
} else {
$dynamicMsg = $dynamic->chat->messages()->create([
'user_id' => null,
'content' => "<user:{$user->id}> suggested \"{$mutation->description}\" for " . ($mutation->amount >= 0 ? '+' : '') . "{$mutation->amount} points on \"{$ledger->name}\" ledger.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
}
broadcast(new \App\Events\MessageSent($dynamicMsg));
});
}
}

View File

@ -52,20 +52,35 @@ class ActivityService
{
if ($entity instanceof Dynamic) {
$chatId = $entity->chat->id;
$dynamic = $entity;
} elseif ($entity instanceof Ledger) {
$chatId = $entity->dynamic->chat->id;
$dynamic = $entity->dynamic;
$chatId = $dynamic->chat->id;
} else {
return [];
}
$participants = $dynamic->participants()->withPivot('display_name')->get();
$participantsMap = $participants->reduce(function ($acc, $p) {
$acc[$p->id] = $p->pivot->display_name ?? $p->name;
return $acc;
}, []);
$messages = Message::where('chat_id', $chatId)
->with(['user', 'subject'])
->latest()
->get();
return $messages->map(function ($message) {
return $messages->map(function ($message) use ($participantsMap) {
$messageData = $message->toArray();
$messageData['url'] = $this->getUrlForMessage($message);
// Resolve <user:id> placeholders to actual names/display names
$messageData['content'] = preg_replace_callback('/<user:(\d+)>/', function ($matches) use ($participantsMap) {
$userId = $matches[1];
return $participantsMap[$userId] ?? "User #{$userId}";
}, $message->content);
return $messageData;
})->all();
}
@ -116,7 +131,7 @@ class ActivityService
'url' => $url,
'unread_count' => count($unread),
'context_activities' => $context,
'new_activities' => $unread,
'new_activities' => array_reverse($unread),
];
}
}

View File

@ -212,7 +212,7 @@ class DatabaseSeeder extends Seeder
// Seed Etiquette Mutations
Mutation::create([
'ledger_id' => $etiquetteLedger->id,
'user_id' => $alice->id,
'user_id' => $bob->id,
'type' => 'penalty',
'amount' => 5,
'description' => 'Interrupted Domina Alice during daily instructions',
@ -221,7 +221,7 @@ class DatabaseSeeder extends Seeder
Mutation::create([
'ledger_id' => $etiquetteLedger->id,
'user_id' => $alice->id,
'user_id' => $bob->id,
'type' => 'penalty',
'amount' => 10,
'description' => 'Forgot correct posture during morning roll call',
@ -230,7 +230,7 @@ class DatabaseSeeder extends Seeder
Mutation::create([
'ledger_id' => $etiquetteLedger->id,
'user_id' => $alice->id,
'user_id' => $bob->id,
'type' => 'penalty',
'amount' => 5,
'description' => 'Spoke out of turn in general chat',

View File

@ -208,3 +208,4 @@
}
}
}
.c-chat__user-link { @apply font-semibold text-blue-500 hover:underline; }

View File

@ -5,23 +5,39 @@ import { useEcho, echoIsConfigured, configureEcho } from '@laravel/echo-vue';
import { route } from 'ziggy-js';
import { Paperclip, Info } from '@lucide/vue';
const props = defineProps<{
chat: {
id: number;
messages: Array<{
const props = withDefaults(
defineProps<{
chat: {
id: number;
user: { id: number; name: string };
content: string;
created_at: string;
media?: Array<{
messages: Array<{
id: number;
url: string;
file_name: string;
mime_type: string;
user: { id: number; name: string } | null;
content: string;
created_at: string;
subject_id?: number | null;
subject_type?: string | null;
subject?: any;
media?: Array<{
id: number;
url: string;
file_name: string;
mime_type: string;
}>;
}>;
};
participants?: Array<{
id: number;
name: string;
pivot?: {
display_name: string | null;
} | null;
}>;
};
}>();
dynamicId: number;
}>(),
{
participants: () => [],
}
);
if (!echoIsConfigured()) {
configureEcho({
@ -50,6 +66,83 @@ useEcho(`chats.${props.chat.id}`, 'MessageSent', (e: any) => {
props.chat.messages.push(e.message);
});
const participantsById = computed(() => {
return props.participants.reduce(
(acc, p) => {
acc[p.id] = p;
return acc;
},
{} as Record<
number,
{
id: number;
name: string;
pivot?: { display_name: string | null } | null;
}
>,
);
});
function parseMessageContent(message: {
content: string;
subject_id?: number | null;
subject_type?: string | null;
subject?: any;
}) {
let content = message.content;
// 1. Replace <user:id> placeholders with links to their dynamic profile
const userRegex = /<user:(\d+)>/g;
content = content.replace(userRegex, (match, userId) => {
const user = participantsById.value[Number(userId)];
if (user) {
const url = route('dynamics.users.show', [props.dynamicId, Number(userId)]);
return `<a href="${url}" class="c-chat__user-link font-semibold text-blue-500 hover:underline">${
user.pivot?.display_name ?? user.name
}</a>`;
}
return `User #${userId}`;
});
// 2. Link subjects if found in the text
if (message.subject_id && message.subject_type) {
if (
message.subject_type === 'App\\Models\\Mutation' ||
message.subject_type === 'App\\Models\\Ledger'
) {
const ledgerId =
message.subject_type === 'App\\Models\\Mutation'
? message.subject?.ledger_id
: message.subject?.id;
const ledgerName =
message.subject_type === 'App\\Models\\Mutation'
? message.subject?.ledger?.name
: message.subject?.name;
if (ledgerId && ledgerName) {
const ledgerUrl = route('dynamics.ledgers.show', [
props.dynamicId,
ledgerId,
]);
const escapedName = ledgerName.replace(
/[-\/\\^$*+?.()|[\]{}]/g,
'\\$&',
);
const nameRegex = new RegExp(`"${escapedName}"`, 'g');
content = content.replace(
nameRegex,
`"<a href="${ledgerUrl}" class="c-chat__subject-link font-semibold text-blue-500 hover:underline">${ledgerName}</a>"`,
);
}
}
}
return content;
}
function handleFileChange(event: Event) {
const files = (event.target as HTMLInputElement).files;
if (files) {
@ -65,7 +158,10 @@ function removeFile(index: number) {
const currentUser = computed(() => usePage().props.auth?.user);
function isOwnMessage(messageUserId: number): boolean {
function isOwnMessage(messageUserId: number | null): boolean {
if (messageUserId === null) {
return false;
}
return currentUser.value && currentUser.value.id === messageUserId;
}
@ -107,17 +203,16 @@ function closeLightbox() {
:class="[
'c-chat__message',
{
'c-chat__message--system':
message.user.id === 0,
'c-chat__message--own': isOwnMessage(message.user.id),
'c-chat__message--other': !isOwnMessage(
message.user.id,
'c-chat__message--system': message.user === null,
'c-chat__message--own': isOwnMessage(message.user?.id),
'c-chat__message--other': message.user !== null && !isOwnMessage(
message.user?.id,
),
},
]"
>
<!-- Standard User Chat Message -->
<template v-if="!message.content.startsWith('System:')">
<template v-if="message.user">
<div class="c-chat__message-header">
<span class="c-chat__message-author">{{
message.user.name
@ -166,9 +261,10 @@ function closeLightbox() {
<template v-else>
<div class="c-chat__system-inner">
<Info class="c-chat__system-icon" />
<span class="c-chat__system-text">
{{ message.content.replace(/^System:\s*/, '') }}
</span>
<span
class="c-chat__system-text"
v-html="parseMessageContent(message)"
></span>
<span class="c-chat__system-time">
{{
new Date(message.created_at).toLocaleTimeString(

View File

@ -1,113 +0,0 @@
<script setup lang="ts">
import { useForm } from '@inertiajs/vue3';
import { route } from 'ziggy-js';
const props = defineProps<{
dynamicId: number;
participant: {
id: number;
name: string;
display_name: string | null;
};
}>();
const form = useForm({
display_name: props.participant.display_name ?? '',
});
function submit() {
form.put(route('dynamics.participant.update', props.dynamicId));
}
</script>
<template>
<div class="c-display-name-form">
<h4 class="c-display-name-form__title">
Display Name for {{ participant.name }}
</h4>
<form @submit.prevent="submit" class="c-display-name-form__form">
<div class="c-display-name-form__field">
<label
for="display_name"
class="c-display-name-form__label"
>
Dynamic-specific Display Name
</label>
<input
v-model="form.display_name"
id="display_name"
type="text"
class="c-display-name-form__input"
/>
<div
v-if="form.errors.display_name"
class="c-display-name-form__error"
>
{{ form.errors.display_name }}
</div>
</div>
<div class="c-display-name-form__actions">
<button
type="submit"
:disabled="form.processing"
class="c-display-name-form__submit-btn"
>
Save
</button>
</div>
</form>
</div>
</template>
<style scoped>
@reference '../../css/app.css';
.c-display-name-form {
@apply mt-8;
}
.c-display-name-form__title {
@apply text-lg font-medium;
color: var(--foreground);
}
.c-display-name-form__form {
@apply mt-4 space-y-4;
}
.c-display-name-form__field {
@apply block;
}
.c-display-name-form__label {
@apply block text-sm font-medium;
color: var(--foreground);
}
.c-display-name-form__input {
@apply mt-1 block w-full rounded-md border shadow-sm focus:border-indigo-500 focus:ring-indigo-500;
border-color: var(--border);
background-color: var(--background);
color: var(--foreground);
}
.c-display-name-form__error {
@apply text-sm;
color: var(--destructive);
}
.c-display-name-form__actions {
@apply flex items-center gap-4;
}
.c-display-name-form__submit-btn {
@apply inline-flex items-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900;
background-color: var(--primary);
color: var(--primary-foreground);
&:hover {
opacity: 0.9;
}
}
</style>

View File

@ -0,0 +1,47 @@
<script setup lang="ts">
import { useForm } from '@inertiajs/vue3';
import { route } from 'ziggy-js';
import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import InputError from '@/components/InputError.vue';
const props = defineProps<{
dynamic: {
id: number;
name: string;
pivot: {
display_name: string | null;
};
};
}>();
const form = useForm({
display_name: props.dynamic.pivot?.display_name ?? '',
});
function submit() {
form.put(route('dynamics.participant.update', props.dynamic.id), {
preserveScroll: true,
});
}
</script>
<template>
<form @submit.prevent="submit" class="flex flex-col sm:flex-row items-start sm:items-center gap-4 p-4 border rounded-lg bg-card text-card-foreground">
<div class="flex-1 w-full">
<div class="font-medium text-sm mb-1">{{ dynamic.name }}</div>
<Input
v-model="form.display_name"
class="w-full"
placeholder="Enter custom display name"
required
/>
<InputError class="mt-1" :message="form.errors.display_name" />
</div>
<div class="sm:self-end">
<Button type="submit" size="sm" :disabled="form.processing">
Save
</Button>
</div>
</form>
</template>

View File

@ -174,7 +174,7 @@ function getAmountClass(amount: number): string {
</button>
</div>
<Chat :chat="mutation.chat" />
<Chat :chat="mutation.chat" :dynamic-id="dynamicId" :participants="participants" />
</li>
</ul>
<div v-if="mutations.length === 0" class="c-mutation-list__empty">

View File

@ -107,11 +107,11 @@ function formatTime(isoString: string): string {
<!-- Unread Separator Line -->
<div
v-if="entity.context_activities.length > 0"
v-if="entity.new_activities.length > 0"
class="c-dashboard__divider"
>
<span class="c-dashboard__divider-text"
>New Activity Below</span
>NEW</span
>
</div>
@ -129,7 +129,6 @@ function formatTime(isoString: string): string {
<span class="c-dashboard__activity-time">
{{ formatTime(activity.created_at) }}
</span>
<span class="c-dashboard__new-badge">NEW</span>
</div>
<p class="c-dashboard__activity-desc">
{{ activity.content }}

View File

@ -2,10 +2,8 @@
import Chat from '@/components/Chat.vue';
import ParticipantsList from '@/components/ParticipantsList.vue';
import LedgerList from '@/components/LedgerList.vue';
import DisplayNameForm from '@/components/DisplayNameForm.vue';
import { Head, Link as InertiaLink, usePage } from '@inertiajs/vue3';
import { Head, Link as InertiaLink } from '@inertiajs/vue3';
import { route } from 'ziggy-js';
import { computed } from 'vue';
const props = defineProps<{
dynamic: {
@ -25,17 +23,6 @@ const props = defineProps<{
isOwner: boolean;
}>();
const currentUser = computed(() => {
const page = usePage();
const authUser = page.props.auth.user;
const participant = props.dynamic.participants.find(p => p.id === authUser.id);
return {
id: authUser.id,
name: authUser.name,
display_name: participant?.pivot?.display_name ?? null,
};
});
const breadcrumbs = [
{
@ -71,7 +58,7 @@ const breadcrumbs = [
</div>
<!-- Dynamic Chat -->
<Chat :chat="dynamic.chat" />
<Chat :chat="dynamic.chat" :participants="dynamic.participants" :dynamic-id="dynamic.id" />
<!-- Participants Component -->
<ParticipantsList :participants="dynamic.participants" />
@ -79,9 +66,6 @@ const breadcrumbs = [
<!-- Ledgers List Component -->
<LedgerList :dynamic-id="dynamic.id" :ledgers="dynamic.ledgers" />
<!-- Display Name Form -->
<DisplayNameForm :dynamic-id="dynamic.id" :participant="currentUser" />
<div v-if="isOwner" class="mt-8 flex gap-4">
<InertiaLink :href="route('dynamics.invitations.create', dynamic.id)" class="c-dynamic-show__action-btn">
Invite User

View File

@ -0,0 +1,260 @@
<script setup lang="ts">
import { Head, Link as InertiaLink } from '@inertiajs/vue3';
import { route } from 'ziggy-js';
const props = defineProps<{
dynamic: {
id: number;
name: string;
};
participant: {
id: number;
name: string;
display_name: string | null;
role: string;
};
mutations: Array<{
id: number;
ledger_id: number;
ledger: {
id: number;
name: string;
alignment: string;
};
amount: number;
description: string;
status: string;
created_at: string;
}>;
}>();
const breadcrumbs = [
{
name: 'Dynamics',
href: route('dynamics.index'),
},
{
name: props.dynamic.name,
href: route('dynamics.show', props.dynamic.id),
},
{
name: props.participant.display_name ?? props.participant.name,
href: route('dynamics.users.show', [props.dynamic.id, props.participant.id]),
},
];
function getAmountClass(amount: number, alignment: string): string {
if (alignment === 'positive') {
return amount > 0
? 'c-participant-show__activity-amount--positive'
: 'c-participant-show__activity-amount--negative';
}
if (alignment === 'negative') {
return amount < 0
? 'c-participant-show__activity-amount--positive'
: 'c-participant-show__activity-amount--negative';
}
return 'c-participant-show__activity-amount--neutral';
}
</script>
<template>
<Head :title="participant.display_name ?? participant.name" />
<div class="c-participant-show">
<div class="c-participant-show__container">
<!-- Header Card -->
<div class="c-participant-show__card">
<div class="c-participant-show__body">
<div class="flex justify-between items-center">
<div>
<span class="c-participant-show__role-badge">
{{ participant.role }}
</span>
<h3 class="c-participant-show__title mt-1">
{{ participant.display_name ?? participant.name }}
</h3>
<p v-if="participant.display_name" class="c-participant-show__subtitle">
Real Name: {{ participant.name }}
</p>
</div>
<InertiaLink :href="route('dynamics.show', dynamic.id)" class="c-participant-show__back-btn">
Back to Dynamic
</InertiaLink>
</div>
</div>
</div>
<!-- Recent Activity Block -->
<div class="c-participant-show__activity mt-8">
<h4 class="c-participant-show__activity-title">Recent Activity</h4>
<div v-if="mutations.length > 0" class="c-participant-show__activity-list mt-4">
<div
v-for="mutation in mutations"
:key="mutation.id"
class="c-participant-show__activity-item"
>
<div class="flex justify-between items-start">
<div>
<InertiaLink
:href="route('dynamics.ledgers.show', [dynamic.id, mutation.ledger_id])"
class="c-participant-show__activity-ledger"
>
{{ mutation.ledger.name }}
</InertiaLink>
<p class="c-participant-show__activity-desc mt-1">
{{ mutation.description }}
</p>
</div>
<div class="text-right">
<span
:class="getAmountClass(mutation.amount, mutation.ledger.alignment)"
class="c-participant-show__activity-amount"
>
{{ mutation.amount > 0 ? '+' : '' }}{{ mutation.amount }}
</span>
<div class="c-participant-show__activity-meta mt-1">
<span
:class="{
'c-participant-show__activity-status--pending': mutation.status === 'pending',
'c-participant-show__activity-status--approved': mutation.status === 'approved',
'c-participant-show__activity-status--rejected': mutation.status === 'rejected',
}"
class="c-participant-show__activity-status"
>
{{ mutation.status }}
</span>
<span class="c-participant-show__activity-time ml-2">
{{ new Date(mutation.created_at).toLocaleDateString() }}
</span>
</div>
</div>
</div>
</div>
</div>
<div v-else class="c-participant-show__empty mt-4">
No recent activity found for this participant.
</div>
</div>
</div>
</div>
</template>
<style scoped>
@reference "../../../css/app.css";
.c-participant-show {
@apply py-12;
}
.c-participant-show__container {
@apply mx-auto max-w-7xl sm:px-6 lg:px-8;
}
.c-participant-show__card {
@apply overflow-hidden;
background-color: var(--card);
border: 1px solid var(--border);
border-radius: var(--radius);
}
.c-participant-show__body {
@apply p-6;
color: var(--foreground);
}
.c-participant-show__role-badge {
@apply inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-semibold uppercase tracking-wider;
background-color: var(--primary);
color: var(--primary-foreground);
opacity: 0.8;
}
.c-participant-show__title {
@apply text-2xl font-bold;
}
.c-participant-show__subtitle {
@apply mt-1 text-sm;
color: var(--muted-foreground);
}
.c-participant-show__back-btn {
@apply inline-flex items-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900 dark:bg-gray-200 dark:text-gray-800 dark:hover:bg-white dark:focus:bg-white dark:focus:ring-offset-gray-800 dark:active:bg-gray-300;
}
.c-participant-show__activity-title {
@apply text-lg font-medium;
color: var(--foreground);
}
.c-participant-show__activity-list {
@apply space-y-4;
}
.c-participant-show__activity-item {
@apply p-4;
background-color: var(--card);
border: 1px solid var(--border);
border-radius: var(--radius);
}
.c-participant-show__activity-ledger {
@apply font-semibold hover:underline text-sm;
color: var(--primary);
}
.c-participant-show__activity-desc {
@apply text-sm;
color: var(--foreground);
}
.c-participant-show__activity-amount {
@apply font-bold text-sm;
}
.c-participant-show__activity-amount--positive {
@apply text-green-500;
}
.c-participant-show__activity-amount--negative {
@apply text-red-500;
}
.c-participant-show__activity-amount--neutral {
@apply text-neutral-500;
}
.c-participant-show__activity-meta {
@apply flex items-center justify-end text-xs;
}
.c-participant-show__activity-status {
@apply rounded px-1.5 py-0.5 text-[9px] font-medium tracking-wider uppercase;
}
.c-participant-show__activity-status--pending {
@apply bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400;
}
.c-participant-show__activity-status--approved {
@apply bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400;
}
.c-participant-show__activity-status--rejected {
@apply bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400;
}
.c-participant-show__activity-time {
color: var(--muted-foreground);
}
.c-participant-show__empty {
@apply text-sm text-center py-8;
color: var(--muted-foreground);
}
</style>

View File

@ -6,6 +6,7 @@ import ProfileController from '@/actions/App/Http/Controllers/Settings/ProfileCo
import DeleteUser from '@/components/DeleteUser.vue';
import Heading from '@/components/Heading.vue';
import InputError from '@/components/InputError.vue';
import DynamicDisplayNameItem from '@/components/DynamicDisplayNameItem.vue';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
@ -23,6 +24,18 @@ defineOptions({
},
});
defineProps<{
mustVerifyEmail: boolean;
status: string | null;
dynamics: Array<{
id: number;
name: string;
pivot: {
display_name: string | null;
};
}>;
}>();
const page = usePage();
const user = computed(() => page.props.auth.user);
</script>
@ -99,6 +112,27 @@ const user = computed(() => page.props.auth.user);
>
</div>
</Form>
<!-- Dynamic-Specific Display Names Section -->
<div class="pt-8 border-t">
<Heading
variant="small"
title="Dynamic Display Names"
description="Customize your display name for each of your dynamics"
/>
<div class="mt-6 space-y-4">
<div v-if="dynamics && dynamics.length > 0" class="space-y-4">
<DynamicDisplayNameItem
v-for="dyn in dynamics"
:key="dyn.id"
:dynamic="dyn"
/>
</div>
<p v-else class="text-sm text-muted-foreground">
You are not a participant in any dynamics yet.
</p>
</div>
</div>
</div>
<DeleteUser />

View File

@ -27,6 +27,7 @@ Route::middleware(['auth', 'verified'])->group(function () {
Route::post('/chats/{chat}/messages', [MessageController::class, 'store'])->name('chats.messages.store');
Route::put('/dynamics/{dynamic}/participant', [\App\Http\Controllers\ParticipantController::class, 'update'])->name('dynamics.participant.update');
Route::get('/dynamics/{dynamic}/users/{user}', [\App\Http\Controllers\ParticipantController::class, 'show'])->name('dynamics.users.show');
});
Route::get('/invitations/accept/{token}', [\App\Http\Controllers\DynamicInvitationController::class, 'accept'])

View File

@ -99,5 +99,5 @@ test('only the user with the specified email address can accept the link', funct
// Verify system notification is added to Dynamic activity chat
$chatMessages = $dynamic->chat->messages;
expect($chatMessages)->not->toBeEmpty();
expect($chatMessages->last()->content)->toBe("{$invitee->name} joined the Dynamic as a EDITOR");
expect($chatMessages->last()->content)->toBe("<user:{$invitee->id}> joined the Dynamic as a EDITOR");
});

View File

@ -32,11 +32,13 @@ test('owner can create a mutation which is automatically approved and does not s
// Verify chat messages (should NOT say "approved" or "Approved")
$mutationChatMessages = $mutation->chat->messages;
expect($mutationChatMessages)->toHaveCount(1);
expect($mutationChatMessages->first()->content)->toBe("System: Entry was created by {$owner->name}.");
expect($mutationChatMessages->first()->user_id)->toBeNull();
expect($mutationChatMessages->first()->content)->toBe("Entry was created by <user:{$owner->id}>.");
$dynamicChatMessages = $dynamic->chat->messages;
expect($dynamicChatMessages)->toHaveCount(1);
expect($dynamicChatMessages->first()->content)->toBe("System: {$owner->name} added entry \"Direct point reward\" for +15 points on \"{$ledger->name}\" ledger.");
expect($dynamicChatMessages->first()->user_id)->toBeNull();
expect($dynamicChatMessages->first()->content)->toBe("<user:{$owner->id}> added entry \"Direct point reward\" for +15 points on \"{$ledger->name}\" ledger.");
});
test('non-owner participant creates a suggestion which defaults to pending and says suggested', function () {
@ -68,11 +70,13 @@ test('non-owner participant creates a suggestion which defaults to pending and s
// Verify chat messages
$mutationChatMessages = $mutation->chat->messages;
expect($mutationChatMessages)->toHaveCount(1);
expect($mutationChatMessages->first()->content)->toBe("System: Suggestion was created by {$participant->name}.");
expect($mutationChatMessages->first()->user_id)->toBeNull();
expect($mutationChatMessages->first()->content)->toBe("Suggestion was created by <user:{$participant->id}>.");
$dynamicChatMessages = $dynamic->chat->messages;
expect($dynamicChatMessages)->toHaveCount(1);
expect($dynamicChatMessages->first()->content)->toBe("System: {$participant->name} suggested \"Suggested point reward\" for +10 points on \"{$ledger->name}\" ledger.");
expect($dynamicChatMessages->first()->user_id)->toBeNull();
expect($dynamicChatMessages->first()->content)->toBe("<user:{$participant->id}> suggested \"Suggested point reward\" for +10 points on \"{$ledger->name}\" ledger.");
});
test('owner can approve a pending suggestion and it is updated and logged', function () {
@ -110,8 +114,10 @@ test('owner can approve a pending suggestion and it is updated and logged', func
$mutationChatMessages = $mutation->chat->messages;
// Note: one from boot created (empty or via seeder, but in our factory it starts with 0 messages if not manually logged,
// actually our model booted hook creates the chat but doesn't log on boot, the update method creates 1 message)
expect($mutationChatMessages->last()->content)->toBe("System: Suggestion was APPROVED by {$owner->name}.");
expect($mutationChatMessages->last()->user_id)->toBeNull();
expect($mutationChatMessages->last()->content)->toBe("Suggestion was APPROVED by <user:{$owner->id}>.");
$dynamicChatMessages = $dynamic->chat->messages;
expect($dynamicChatMessages->last()->content)->toBe("System: {$owner->name} APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
expect($dynamicChatMessages->last()->user_id)->toBeNull();
expect($dynamicChatMessages->last()->content)->toBe("<user:{$owner->id}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
});

View File

@ -0,0 +1,95 @@
<?php
use App\Models\User;
use App\Models\Dynamic;
use App\Models\Ledger;
use App\Models\Mutation;
test('authenticated participant can view another participant detail page in dynamic', function () {
$owner = User::factory()->create();
$participant = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner', 'display_name' => 'The Boss']);
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
$this->actingAs($owner);
$response = $this->get(route('dynamics.users.show', [$dynamic->id, $participant->id]));
$response->assertOk();
$response->assertInertia(fn ($page) => $page
->component('Participants/Show')
->has('dynamic')
->where('participant.id', $participant->id)
->where('participant.name', $participant->name)
->where('participant.display_name', null)
->where('participant.role', 'participant')
->has('mutations')
);
});
test('non-participant cannot view participant detail page in dynamic', function () {
$owner = User::factory()->create();
$participant = User::factory()->create();
$outsider = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
$this->actingAs($outsider);
$response = $this->get(route('dynamics.users.show', [$dynamic->id, $participant->id]));
$response->assertStatus(403);
});
test('participant detail page displays their recent mutations in dynamic', function () {
$owner = User::factory()->create();
$participant = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant->id, ['role' => 'participant', 'display_name' => 'Bitch']);
// Create mutations in this dynamic
$mutation1 = Mutation::factory()->create([
'ledger_id' => $ledger->id,
'user_id' => $participant->id,
'amount' => 10,
'description' => 'Chore 1',
]);
$mutation2 = Mutation::factory()->create([
'ledger_id' => $ledger->id,
'user_id' => $participant->id,
'amount' => -5,
'description' => 'Infraction 1',
]);
// Create a mutation in another dynamic (should NOT be displayed)
$otherDynamic = Dynamic::factory()->create();
$otherLedger = Ledger::factory()->create(['dynamic_id' => $otherDynamic->id]);
$otherDynamic->participants()->attach($participant->id, ['role' => 'participant']);
$mutation3 = Mutation::factory()->create([
'ledger_id' => $otherLedger->id,
'user_id' => $participant->id,
'amount' => 100,
'description' => 'Other dynamic chore',
]);
$this->actingAs($owner);
$response = $this->get(route('dynamics.users.show', [$dynamic->id, $participant->id]));
$response->assertOk();
$response->assertInertia(fn ($page) => $page
->component('Participants/Show')
->where('participant.display_name', 'Bitch')
->has('mutations', 2)
->where('mutations.0.description', 'Infraction 1') // Ordered latest first
->where('mutations.1.description', 'Chore 1')
);
});