refactor(portal): move composables, types, schemas; drop duplicates
Composables (apps/portal/src/composables → apps/app/src/composables/):
- useFormDraft, publicFormInjection → composables/ (root, used by
shared/public-form components)
- api/usePublicForm, api/usePublicFormSections,
api/usePublicFormTimeSlots → composables/api/ (no collisions)
- api/usePortalShifts, api/usePortalProfile, api/useVolunteerRegistration
→ composables/api/portal/ (subfolder per WS-3 PR-B1 charter to
leave room for organizer-side namesakes without clashes)
- api/useMfa → DELETED (apps/app version is a strict superset
with extra invalidateQueries calls and the admin-reset mutation)
Types (apps/portal/src/types → apps/app/src/types/):
- api, portal-shift, portal, registration → moved
- mfa → DELETED (byte-identical to apps/app/src/types/mfa.ts)
Schemas:
- apps/portal/src/schemas/registrationSchema.ts → apps/app/src/schemas/
Utils:
- deviceFingerprint, paginationMeta → DELETED (byte-identical
duplicates already in apps/app/src/utils/)
Lib:
- apps/portal/src/lib/{axios,query-client}.ts → DELETED. apps/app's
callback-bound axios (post-PR-A) and query-client are the
canonical versions. Portal pages currently importing
`@/lib/axios#apiClient` resolve to apps/app's apiClient with no
behavioral change for cookie-based requests.
Tests: 4 composable specs (useFormDraft x2, usePublicFormSections,
usePublicFormTimeSlots) moved into __tests__/ subdirs alongside
their composables.
@form-schema imports inside the moved files rewritten to
@/composables/forms/*.
Vitest now: 23 files / 162 tests passing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
37
apps/app/src/composables/publicFormInjection.ts
Normal file
37
apps/app/src/composables/publicFormInjection.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { InjectionKey, Ref } from 'vue'
|
||||
import { computed, inject, provide } from 'vue'
|
||||
|
||||
// Page-level provide/inject for the public form token. Sibling-endpoint
|
||||
// fetches (time-slots, sections) read it instead of receiving it as a
|
||||
// prop through FieldRenderer, which would couple every renderer to every
|
||||
// new sibling resource.
|
||||
export const PUBLIC_FORM_TOKEN_KEY: InjectionKey<Ref<string>> = Symbol('PublicFormToken')
|
||||
|
||||
export function providePublicFormToken(token: Ref<string>): void {
|
||||
provide(PUBLIC_FORM_TOKEN_KEY, token)
|
||||
}
|
||||
|
||||
export function usePublicFormToken(): Ref<string> {
|
||||
const token = inject(PUBLIC_FORM_TOKEN_KEY)
|
||||
if (!token) {
|
||||
throw new Error('usePublicFormToken: no token provided. Did you forget providePublicFormToken in the page?')
|
||||
}
|
||||
|
||||
return token
|
||||
}
|
||||
|
||||
// Page-level provide/inject for the active form locale. Used by
|
||||
// option-bearing field renderers (FieldRadio / FieldSelect /
|
||||
// FieldMultiselect / FieldCheckboxList) to resolve per-option
|
||||
// translations[locale] over the default option label (WS-5d §17.6).
|
||||
// Falls back to 'nl' (Crewli's default schema locale) when no provider
|
||||
// is on the tree — keeps standalone component tests light.
|
||||
export const PUBLIC_FORM_LOCALE_KEY: InjectionKey<Ref<string>> = Symbol('PublicFormLocale')
|
||||
|
||||
export function providePublicFormLocale(locale: Ref<string>): void {
|
||||
provide(PUBLIC_FORM_LOCALE_KEY, locale)
|
||||
}
|
||||
|
||||
export function usePublicFormLocale(): Ref<string> {
|
||||
return inject(PUBLIC_FORM_LOCALE_KEY, computed(() => 'nl'))
|
||||
}
|
||||
Reference in New Issue
Block a user