|
| 1 | +<script lang="ts"> |
| 2 | + import Button from "$lib/components/primitives/button/button.svelte"; |
| 3 | + import type { User } from "$lib/model/backend"; |
| 4 | + import { getNameAsString } from "$lib/utils/common-helper"; |
| 5 | + import { cn } from "$lib/utils/shadcn-helper"; |
| 6 | + import Trash from "lucide-svelte/icons/trash"; |
| 7 | +
|
| 8 | + interface Props { |
| 9 | + member: User; |
| 10 | + isCurrentUser: boolean; |
| 11 | + isInvitationPending: boolean; |
| 12 | + isAdminView: boolean; |
| 13 | + } |
| 14 | +
|
| 15 | + let { member, isCurrentUser, isInvitationPending, isAdminView }: Props = $props(); |
| 16 | + const role = member.isAdmin ? "Admin" : "Member"; |
| 17 | + const isRoleReadonly = isCurrentUser || !isAdminView; |
| 18 | +</script> |
| 19 | + |
| 20 | +<div class="flex flex-col md:flex-row items-center justify-between px-4 gap-4"> |
| 21 | + <div class="flex flex-col"> |
| 22 | + <h3> |
| 23 | + {getNameAsString(member)} |
| 24 | + {#if isCurrentUser} |
| 25 | + <span class="text-gray-400"> - You</span> |
| 26 | + {/if} |
| 27 | + </h3> |
| 28 | + <span class="text-hint text-primary">{member.email}</span> |
| 29 | + </div> |
| 30 | + <div class="flex flex-row gap-2.5 items-center"> |
| 31 | + {#if isInvitationPending} |
| 32 | + <span class="text-hint">Invitation Pending ...</span> |
| 33 | + {/if} |
| 34 | + <Button |
| 35 | + class={cn( |
| 36 | + "w-[7.7rem]", |
| 37 | + isRoleReadonly |
| 38 | + ? "hover:bg-transparent hover:cursor-default" |
| 39 | + : "bg-gray-100 border border-gray-300 hover:bg-gray-200", |
| 40 | + )} |
| 41 | + variant={isRoleReadonly ? "ghost" : "secondary"} |
| 42 | + > |
| 43 | + <!-- Take maximum space so that text is left aligned --> |
| 44 | + <span class="flex w-full">Role: {role}</span> |
| 45 | + </Button> |
| 46 | + {#if isAdminView} |
| 47 | + <Button |
| 48 | + class="bg-gray-100 border border-gray-300 hover:bg-gray-200 size-10" |
| 49 | + disabled={isCurrentUser} |
| 50 | + > |
| 51 | + <Trash class=" text-red-500 !size-6" /> |
| 52 | + </Button> |
| 53 | + {/if} |
| 54 | + </div> |
| 55 | +</div> |
0 commit comments