Skip to content

Commit

Permalink
fix: handle missing user in ProjectShow
Browse files Browse the repository at this point in the history
  • Loading branch information
keenthekeen committed Aug 3, 2024
1 parent f0ef1c7 commit d8ee496
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public function show(Request $request, Project $project) {
$project->load(['user', 'department', 'documents', 'participants', 'participants.user']);
$project->user->makeHidden('id', 'student_id', 'profile_photo_url');
$project->participants->transform(function (ProjectParticipant $participant) use ($canUpdateProject) {
$participant->user->makeHidden('id', 'profile_photo_url');
$participant->user?->makeHidden('id', 'profile_photo_url');
if (!$canUpdateProject) {
$participant->user->makeHidden('student_id');
$participant->user?->makeHidden('student_id');
}

return $participant;
Expand Down
8 changes: 4 additions & 4 deletions resources/js/Pages/ProjectShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
</template>
</div>
<ImportParticipantDialog :show-modal="showImportParticipantDialog" :project="item" @close="showImportParticipantDialog = false"/>
<StudentIdDialog :show-modal="Boolean(showStudentIdDialog)" :list="item.participants.map(p => p.user.student_id)"
<StudentIdDialog :show-modal="Boolean(showStudentIdDialog)" :list="item.participants.map(p => p.user?.student_id)"
@close="showStudentIdDialog = false" @selected="addParticipant($event)"/>
<div class="border-t border-gray-200">
<dl>
Expand All @@ -353,10 +353,10 @@
<dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">
<ol class="list-decimal" v-if="participantsGrouped[type]">
<li v-for="e in participantsGrouped[type]">
{{ e.user.name }}
<span v-if="e.user.student_id" class="ml-4 text-gray-700">เลขประจำตัวนิสิต {{ e.user.student_id }}</span>
{{ e.user?.name }}
<span v-if="e.user?.student_id" class="ml-4 text-gray-700">เลขประจำตัวนิสิต {{ e.user?.student_id }}</span>
<span v-if="e.title" class="ml-4 px-1.5 py-0.5 rounded bg-gray-200">{{ e.title }}</span>
<XMarkIcon v-if="e.user.student_id && !((type === 'organizer') && (participantsGrouped[type].length <= 1))"
<XMarkIcon v-if="e.user?.student_id && !((type === 'organizer') && (participantsGrouped[type].length <= 1))"
class="inline-block ml-1 h-5 text-red-400 cursor-pointer" @click="removeParticipant(e)"/>
</li>
</ol>
Expand Down

0 comments on commit d8ee496

Please sign in to comment.