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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | 46x 116x 1x 1x 1x 1x 1x 1x 1x 285x 1x 1x 1x 1x 62x 62x 1x 1x 2x 3x 1x 1x 1x 11x 23x 23x 23x 23x 23x 23x 23x 23x 469x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 582x 23x 11x 23x 11x 23x 7x 23x 23x 24x 24x 24x 24x 24x 22x 141x 125x 109x 101x 2x 1x 1x 24x 23x 45x 45x 372x 23x 124x 2084x 139x 46x 10x 10x 10x 55x 55x 6x 49x 4x 45x 6x 39x 39x 5x 3x 2x 1x 1x 10x 11x 3x 5x 5x 5x 1x 4x 3x 1x 23x 57x 11x 11x 11x 1x 1x 10x 10x 10x 4x 6x 6x 1x 5x 10x 3x 3x 3x 2x 3x 3x 3x 3x 9x | <template>
<SpaceLayout
:space="space"
compact
:member-flow-slug="memberFlowSlug"
:loading="loading"
:loading-theme="loadingTheme"
>
<div v-if="loading || formLoading" class="space-state">
<div class="spinner-border" role="status" aria-hidden="true"></div>
</div>
<div v-else-if="notAvailable" class="space-state" data-testid="space-not-found">
<h1>{{ t('space.notFoundTitle') }}</h1>
<p>{{ t('space.notFoundText') }}</p>
</div>
<div v-else-if="loadError || formError" class="space-state" data-testid="space-load-error">
<p>{{ t('space.loadError') }}</p>
</div>
<template v-else-if="space">
<h1 class="join-title">{{ t('space.joinPageTitle').replace('{flow}', space.name) }}</h1>
<!-- Step 1: a Flows account -->
<section v-if="!authStore.isAuthenticated" class="join-step" data-testid="join-step-account">
<p class="join-step-label">{{ t('space.joinStep1') }}</p>
<p>{{ t('space.joinAccountText') }}</p>
<div class="d-flex flex-wrap gap-2">
<router-link
:to="{ path: '/signup', query: { redirect: route.path } }"
class="btn space-button"
data-testid="join-signup"
>
{{ t('space.joinCreateAccount') }}
</router-link>
<router-link
:to="{ path: '/login', query: { redirect: route.path } }"
class="btn btn-outline-secondary"
data-testid="join-signin"
>
{{ t('space.joinSignIn') }}
</router-link>
</div>
</section>
<template v-else-if="form">
<div v-if="form.isMember" class="join-notice" data-testid="join-already-member">
<p>{{ t('space.joinAlreadyMember') }}</p>
<router-link :to="flowRoute(space.slug, 'home')" class="btn space-button">
{{ t('space.openInFlows') }}
</router-link>
</div>
<div v-else-if="sent" class="join-notice" data-testid="join-sent">
<font-awesome-icon icon="check" class="me-2" />
{{ t('space.joinSent').replace('{flow}', space.name) }}
</div>
<div
v-else-if="form.request?.status === 'pending'"
class="join-notice"
data-testid="join-pending"
>
<p>
{{ t('space.joinPending').replace('{date}', formatDate(form.request.createdAt)) }}
</p>
<button
type="button"
class="btn btn-outline-secondary"
:disabled="submitting"
data-testid="join-withdraw"
@click="withdraw"
>
{{ t('space.joinWithdraw') }}
</button>
</div>
<div
v-else-if="form.request?.status === 'banned'"
class="join-notice"
data-testid="join-banned"
>
{{ t('space.joinNotAccepted') }}
</div>
<!-- Step 2: the flow's form and the consents -->
<form v-else class="join-step" data-testid="join-form" @submit.prevent="submit">
<p class="join-step-label">{{ t('space.joinStep2') }}</p>
<div
v-if="form.request?.status === 'refused'"
class="alert alert-secondary"
data-testid="join-refused"
>
{{ t('space.joinRefused') }}
</div>
<div v-for="field in form.fields" :key="field.fieldId" class="mb-3">
<template v-if="fieldType(field) === 'boolean'">
<div class="form-check">
<input
:id="`join-${field.fieldId}`"
v-model="booleanAnswers[field.fieldId!]"
type="checkbox"
class="form-check-input"
/>
<label :for="`join-${field.fieldId}`" class="form-check-label">
{{ fieldText(field.name) }}
</label>
</div>
</template>
<template v-else>
<label
:for="isUploadField(field) ? undefined : `join-${field.fieldId}`"
class="form-label"
>
{{ fieldText(field.name) }}
<span v-if="field.mandatory" class="text-danger" aria-hidden="true">*</span>
</label>
<textarea
v-if="fieldType(field) === 'textarea'"
:id="`join-${field.fieldId}`"
v-model="textAnswers[field.fieldId!]"
class="form-control"
rows="3"
:maxlength="field.length"
:required="field.mandatory"
:placeholder="fieldText(field.placeholder)"
></textarea>
<select
v-else-if="fieldType(field) === 'select'"
:id="`join-${field.fieldId}`"
v-model="textAnswers[field.fieldId!]"
class="form-select"
:required="field.mandatory"
>
<option value="">{{ t('common.select') }}</option>
<option
v-for="option in field.options || []"
:key="optionValue(option)"
:value="optionValue(option)"
>
{{ optionLabel(option) }}
</option>
</select>
<div
v-else-if="fieldType(field) === 'multiselect'"
:id="`join-${field.fieldId}`"
role="group"
>
<div
v-for="option in field.options || []"
:key="optionValue(option)"
class="form-check"
>
<input
:id="`join-${field.fieldId}-${optionValue(option)}`"
v-model="multiAnswers[field.fieldId!]"
type="checkbox"
class="form-check-input"
:value="optionValue(option)"
/>
<label
:for="`join-${field.fieldId}-${optionValue(option)}`"
class="form-check-label"
>
{{ optionLabel(option) }}
</label>
</div>
</div>
<!-- Images and files go to the requester's drafts (UC-SPACE-020.1) -->
<template v-else-if="isUploadField(field)">
<div
v-if="field.placeholder"
class="form-text mt-0 mb-2"
:data-testid="`join-help-${field.fieldId}`"
>
{{ fieldText(field.placeholder) }}
</div>
<ImageField
v-if="fieldType(field) === 'image' || fieldType(field) === 'image_set'"
:model-value="imageAnswer(field)"
:field="field"
:is-editing="true"
:join-slug="slug"
:data-testid="`join-upload-${field.fieldId}`"
@update:model-value="uploadAnswers[field.fieldId!] = $event"
/>
<FileField
v-else
:model-value="fileAnswer(field)"
:field="field"
:is-editing="true"
:join-slug="slug"
:data-testid="`join-upload-${field.fieldId}`"
@update:model-value="uploadAnswers[field.fieldId!] = $event"
/>
</template>
<input
v-else
:id="`join-${field.fieldId}`"
v-model="textAnswers[field.fieldId!]"
:type="inputType(fieldType(field))"
class="form-control"
:maxlength="field.length"
:min="field.min"
:max="field.max"
:step="field.step"
:required="field.mandatory"
:placeholder="fieldText(field.placeholder)"
/>
</template>
</div>
<div class="join-gdpr small" data-testid="join-gdpr">
<p class="mb-1">{{ t('space.joinGdprAccount') }}</p>
<p class="mb-1">{{ t('space.joinGdprFlow').replace('{flow}', space.name) }}</p>
<p v-if="form.privacyContact" class="mb-0">
{{ t('space.joinGdprContact') }}
<a :href="`mailto:${form.privacyContact}`">{{ form.privacyContact }}</a>
</p>
</div>
<div class="form-check my-3">
<input
id="join-consent"
v-model="consent"
type="checkbox"
class="form-check-input"
data-testid="join-consent"
/>
<label for="join-consent" class="form-check-label">
{{ t('space.joinConsent').replace('{flow}', space.name) }}
</label>
</div>
<div v-if="submitError" class="alert alert-danger" role="alert" data-testid="join-error">
{{ submitError }}
</div>
<button
type="submit"
class="btn btn-lg space-button"
:disabled="!consent || submitting"
data-testid="join-submit"
>
{{ t('space.joinSend') }}
</button>
</form>
</template>
</template>
</SpaceLayout>
</template>
<script setup lang="ts">
// @implements UC-SPACE-004.1, UC-SPACE-020.1
import { computed, reactive, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import SpaceLayout from '@/components/SpaceLayout.vue'
import ImageField from '@/components/ImageField.vue'
import FileField from '@/components/FileField.vue'
import { useAuthStore } from '@/stores/auth'
import { useUILanguage } from '@/composables/useUILanguage'
import { useLanguage } from '@/composables/useLanguage'
import { usePublicSpace } from '@/composables/usePublicSpace'
import { useSpaceLanguage } from '@/composables/useSpaceLanguage'
import { flowRoute } from '@/router/flowRoutes'
import {
getJoinForm,
requestMembership,
withdrawMembershipRequest,
type JoinForm
} from '@/services/membershipRequests'
import type { EntityField, FileValue } from '@/stores/entities'
const route = useRoute()
const authStore = useAuthStore()
const { t } = useUILanguage()
const { getTranslation } = useLanguage()
const slug = computed(() => String(route.params.slug))
const { space, loading, loadingTheme, notFound, loadError, memberFlowSlug } = usePublicSpace(slug)
// The form's labels in the space's language (UC-SPACE-018.1)
const { contentLanguage } = useSpaceLanguage(space)
const fieldText = (value: Parameters<typeof getTranslation>[0]) =>
getTranslation(value, contentLanguage.value)
const form = ref<JoinForm | null>(null)
const formLoading = ref(false)
const formNotFound = ref(false)
const formError = ref(false)
const sent = ref(false)
const consent = ref(false)
const submitting = ref(false)
const submitError = ref('')
const textAnswers = reactive<Record<string, string>>({})
const multiAnswers = reactive<Record<string, string[]>>({})
const booleanAnswers = reactive<Record<string, boolean>>({})
/** Image keys and file values, as the item form stores them (UC-SPACE-020.1) */
const uploadAnswers = reactive<Record<string, unknown>>({})
const UPLOAD_TYPES = ['image', 'image_set', 'file', 'file_set']
const isUploadField = (field: EntityField) => UPLOAD_TYPES.includes(fieldType(field))
const imageAnswer = (field: EntityField) =>
uploadAnswers[field.fieldId!] as string | string[] | null
const fileAnswer = (field: EntityField) =>
uploadAnswers[field.fieldId!] as FileValue | FileValue[] | null
const hasValue = (value: unknown) =>
Array.isArray(value) ? value.length > 0 : value !== null && value !== undefined && value !== ''
const notAvailable = computed(
() => notFound.value || formNotFound.value || (!!space.value && !space.value.joinOpen)
)
async function loadForm() {
formLoading.value = true
formNotFound.value = false
formError.value = false
try {
form.value = await getJoinForm(slug.value)
for (const field of form.value.fields) {
if (fieldType(field) === 'multiselect') multiAnswers[field.fieldId!] ??= []
else if (fieldType(field) === 'boolean') booleanAnswers[field.fieldId!] ??= false
else if (isUploadField(field)) uploadAnswers[field.fieldId!] ??= null
else textAnswers[field.fieldId!] ??= ''
}
} catch (err: any) {
if (err.response?.status === 404) formNotFound.value = true
else {
console.error('[SpaceJoinPage] failed to load the join form:', err)
formError.value = true
}
} finally {
formLoading.value = false
}
}
// Step 2 needs a signed-in user and a space that takes requests
watch(
() => [space.value?.joinOpen, authStore.isAuthenticated] as const,
([joinOpen, signedIn]) => {
if (joinOpen && signedIn) void loadForm()
},
{ immediate: true }
)
type Option = string | { value: string; label?: string }
const optionValue = (option: Option) => (typeof option === 'string' ? option : option.value)
const optionLabel = (option: Option) =>
typeof option === 'string' ? option : option.label || option.value
/** The wire type: the UI's EntityField union lacks some API types (multiselect) */
const fieldType = (field: EntityField): string => field.type ?? 'text'
function inputType(type: string): string {
if (type === 'email' || type === 'number' || type === 'date') return type
return 'text'
}
/** The answers as the item form stores them: texts per language, numbers as numbers */
function buildAnswers(): Record<string, unknown> {
const language = form.value?.defaultLanguage || 'en'
const answers: Record<string, unknown> = {}
for (const field of form.value?.fields ?? []) {
const id = field.fieldId!
if (fieldType(field) === 'multiselect') {
if (multiAnswers[id]?.length) answers[id] = [...multiAnswers[id]]
} else if (isUploadField(field)) {
if (hasValue(uploadAnswers[id])) answers[id] = uploadAnswers[id]
} else if (fieldType(field) === 'boolean') {
answers[id] = !!booleanAnswers[id]
} else {
const value = (textAnswers[id] ?? '').toString().trim()
if (!value) continue
if (fieldType(field) === 'text' || fieldType(field) === 'textarea') {
answers[id] = { [language]: value }
} else if (fieldType(field) === 'number') {
answers[id] = Number(value)
} else {
answers[id] = value
}
}
}
return answers
}
function fieldName(fieldId: string | undefined): string {
const field = form.value?.fields.find((f) => f.fieldId === fieldId)
return field ? fieldText(field.name) : ''
}
function errorMessage(err: any): string {
const status = err.response?.status
const data = err.response?.data ?? {}
if (status === 409 && data.error === 'TOO_MANY_PENDING_REQUESTS') {
return t('space.joinTooManyRequests')
}
if (status === 400 && data.fieldId) {
return t('space.joinInvalidField').replace('{field}', fieldName(data.fieldId))
}
return t('space.joinSendError')
}
/** A mandatory image or file not given yet: the browser can't check those */
const missingUpload = computed(() =>
(form.value?.fields ?? []).find(
(field) => field.mandatory && isUploadField(field) && !hasValue(uploadAnswers[field.fieldId!])
)
)
async function submit() {
Iif (!consent.value) return
submitError.value = ''
if (missingUpload.value) {
submitError.value = t('space.joinMissingFile').replace(
'{field}',
fieldText(missingUpload.value.name)
)
return
}
submitting.value = true
try {
await requestMembership(slug.value, buildAnswers())
sent.value = true
} catch (err: any) {
const code = err.response?.data?.error
if (
code === 'REQUEST_ALREADY_PENDING' ||
code === 'ALREADY_MEMBER' ||
code === 'REQUEST_NOT_ALLOWED'
) {
// The state changed elsewhere (another tab, a decision): show it as it is now
await loadForm()
} else {
submitError.value = errorMessage(err)
}
} finally {
submitting.value = false
}
}
async function withdraw() {
submitting.value = true
try {
await withdrawMembershipRequest(slug.value)
} catch (err: any) {
if (err.response?.status !== 404) console.error('[SpaceJoinPage] withdraw failed:', err)
} finally {
submitting.value = false
}
sent.value = false
consent.value = false
await loadForm()
}
function formatDate(iso: string): string {
return new Date(iso).toLocaleDateString()
}
</script>
<style scoped>
.join-title {
font-size: clamp(1.25rem, 4vw, 1.75rem);
margin-bottom: 1.5rem;
}
.join-step-label {
font-weight: 600;
text-transform: uppercase;
font-size: 0.8125rem;
letter-spacing: 0.04em;
opacity: 0.8;
}
.join-notice {
padding: 1rem;
border-left: 4px solid var(--space-secondary);
background: color-mix(in srgb, var(--space-secondary) 12%, transparent);
}
.join-gdpr {
padding: 0.75rem;
border: 1px solid color-mix(in srgb, var(--space-text) 20%, transparent);
border-radius: 0.375rem;
}
</style>
|