All files / src/components/profiles SupportSafetyCard.vue

100% Statements 78/78
100% Branches 0/0
100% Functions 0/0
100% Lines 78/78

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 1811x 1x 1x 1x 1x   1x 1x 1x 1x 1x   1x 1x   1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x   1x 1x 1x 1x 1x   1x 1x 1x 1x       1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x                                                                                                                                                                                
<template>
  <section class="safety-card" data-testid="support-safety-card">
    <header class="safety-header">
      <h3>Support &amp; Safety</h3>
    </header>
 
    <ul class="safety-links">
      <li>
        <SupportEmailLink display-text="Contact Support" />
      </li>
    </ul>
 
    <div class="blocked-section">
      <h4 class="blocked-title">Blocked Users</h4>
 
      <p v-if="loading && !loaded" class="blocked-help">Loading…</p>
      <p
        v-else-if="loadFailed"
        class="blocked-help is-error"
        data-testid="blocked-load-error"
      >
        Couldn't load your blocked users.
        <button type="button" class="link-button" @click="load">Retry</button>
      </p>
      <p
        v-else-if="blocks.length === 0"
        class="blocked-help"
        data-testid="blocked-empty"
      >
        People you block or report in live chat show up here.
      </p>
      <ul v-else class="blocked-list" data-testid="blocked-list">
        <li v-for="user in blocks" :key="user.user_id" class="blocked-row">
          <span class="blocked-name">{{
            user.username || 'Unknown user'
          }}</span>
          <button
            type="button"
            class="unblock-button"
            :data-testid="`unblock-${user.user_id}`"
            :disabled="unblocking === user.user_id"
            @click="unblock(user)"
          >
            Unblock
          </button>
        </li>
      </ul>
 
      <p
        v-if="actionError"
        class="blocked-help is-error"
        role="status"
        data-testid="unblock-error"
      >
        {{ actionError }}
      </p>
    </div>
  </section>
</template>
 
<script setup>
import { computed, onMounted, ref } from 'vue';
import SupportEmailLink from '@/components/SupportEmailLink.vue';
import { useBlockedUsers } from '@/composables/useBlockedUsers';
 
// Profile → Support & Safety (SB-1324): the web counterpart of the iOS
// Profile section — support, and the people you've blocked in chat.
const {
  blocks,
  loaded,
  loading,
  error,
  load,
  unblock: unblockUser,
} = useBlockedUsers();
 
const loadFailed = computed(() => !loaded.value && !!error.value);
const unblocking = ref(null);
const actionError = ref('');
 
async function unblock(user) {
  unblocking.value = user.user_id;
  actionError.value = '';
  try {
    await unblockUser(user.user_id);
  } catch (e) {
    actionError.value = e.message || 'Could not unblock this user';
  } finally {
    unblocking.value = null;
  }
}
 
onMounted(load);
</script>
 
<style scoped>
.safety-card {
  background: rgb(var(--color-card));
  border: 1px solid rgb(var(--color-line));
  border-radius: 12px;
  padding: 20px;
  margin-top: 24px;
}
 
.safety-header h3 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 700;
  color: rgb(var(--color-fg));
}
 
.safety-links {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
}
 
.blocked-title {
  margin: 0 0 6px;
  font-size: 15px;
  font-weight: 600;
  color: rgb(var(--color-fg));
}
 
.blocked-help {
  margin: 0;
  font-size: 13px;
  color: rgb(var(--color-fg-muted));
  line-height: 1.4;
}
 
.blocked-help.is-error {
  color: #b91c1c;
  margin-top: 8px;
}
 
.blocked-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
 
.blocked-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  border-bottom: 1px solid rgb(var(--color-line));
}
 
.blocked-row:last-child {
  border-bottom: none;
}
 
.blocked-name {
  color: rgb(var(--color-fg));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
 
.unblock-button,
.link-button {
  background: none;
  border: none;
  padding: 8px 0;
  color: #2563eb;
  font-weight: 600;
  cursor: pointer;
}
 
.unblock-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
</style>