WS-3 session 1b-i Tier 2. Scope: composables, lib, stores, plugins, types, utils, navigation, main.ts. Mechanical fixes only — predominantly newline-before-return, arrow-parens, antfu/if-newline, padding-line-between-statements, plus one unicorn/prefer-includes (.some(p => x === p) → .includes(x)) in router guards. Excludes (per session prompt): - apps/app/vite.config.ts (Tier 3) - apps/app/themeConfig.ts (Tier 3) - apps/app/vitest.config.ts (Tier 3) - All .vue files (already in Tier 1) Hand-reviewed diffs for the three auth/router-critical files before committing: - src/lib/axios.ts: reviewed clean. Pure mechanical (quote-props on Accept header, curly-strip on single-statement ifs, one blank line before impersonationStore.clearState()). No type-import changes, no logic touched. - src/stores/useAuthStore.ts: reviewed clean. curly-strip + padding before returns. The initialize()/doInitialize() race-condition guard on isInitialized is preserved verbatim. - src/plugins/1.router/guards.ts: reviewed clean. if-newline reformat + one .some() → .includes() rewrite that's behaviorally identical for primitive equality on the guestOnlyPaths string array. Tests + typecheck verified green post-fix: - apps/app vitest: 49 passed (unchanged) - apps/app vue-tsc: clean (unchanged) Lint baseline progression: - Pre-Tier-2: 422 problems (post-Tier-1) - Post-Tier-2: 246 problems Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
146 lines
4.7 KiB
TypeScript
146 lines
4.7 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
|
|
import type { Ref } from 'vue'
|
|
import { apiClient } from '@/lib/axios'
|
|
import type {
|
|
RegistrationFormField,
|
|
RegistrationFormFieldCreateDTO,
|
|
RegistrationFormFieldUpdateDTO,
|
|
} from '@/types/registration-form-field'
|
|
|
|
interface ApiResponse<T> {
|
|
success: boolean
|
|
data: T
|
|
message?: string
|
|
}
|
|
|
|
export function useRegistrationFormFields(orgId: Ref<string>, eventId: Ref<string>) {
|
|
return useQuery({
|
|
queryKey: ['registration-form-fields', eventId],
|
|
queryFn: async () => {
|
|
const { data } = await apiClient.get<{ data: RegistrationFormField[] }>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/registration-fields`,
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
enabled: () => !!orgId.value && !!eventId.value,
|
|
staleTime: Number.POSITIVE_INFINITY,
|
|
})
|
|
}
|
|
|
|
export function useCreateRegistrationFormField(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async (payload: RegistrationFormFieldCreateDTO) => {
|
|
const { data } = await apiClient.post<ApiResponse<RegistrationFormField>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/registration-fields`,
|
|
payload,
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['registration-form-fields', eventId] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useUpdateRegistrationFormField(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ id, ...payload }: RegistrationFormFieldUpdateDTO & { id: string }) => {
|
|
const { data } = await apiClient.put<ApiResponse<RegistrationFormField>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/registration-fields/${id}`,
|
|
payload,
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['registration-form-fields', eventId] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useDeleteRegistrationFormField(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async (id: string) => {
|
|
await apiClient.delete(`/organisations/${orgId.value}/events/${eventId.value}/registration-fields/${id}`)
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['registration-form-fields', eventId] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useReorderRegistrationFormFields(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
let previousFields: RegistrationFormField[] | undefined
|
|
|
|
return useMutation({
|
|
mutationFn: async (orderedIds: string[]) => {
|
|
await apiClient.post(`/organisations/${orgId.value}/events/${eventId.value}/registration-fields/reorder`, {
|
|
ids: orderedIds,
|
|
})
|
|
},
|
|
onMutate: async orderedIds => {
|
|
await queryClient.cancelQueries({ queryKey: ['registration-form-fields', eventId.value] })
|
|
previousFields = queryClient.getQueryData<RegistrationFormField[]>(['registration-form-fields', eventId.value])
|
|
|
|
if (previousFields) {
|
|
const byId = new Map(previousFields.map(f => [f.id, f]))
|
|
|
|
const reordered = orderedIds
|
|
.map(id => byId.get(id))
|
|
.filter((f): f is RegistrationFormField => !!f)
|
|
|
|
queryClient.setQueryData(['registration-form-fields', eventId.value], reordered)
|
|
}
|
|
},
|
|
onError: () => {
|
|
if (previousFields)
|
|
queryClient.setQueryData(['registration-form-fields', eventId.value], previousFields)
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useCreateFieldFromTemplate(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async (templateId: string) => {
|
|
const { data } = await apiClient.post<ApiResponse<RegistrationFormField>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/registration-fields/from-template`,
|
|
{ template_id: templateId },
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['registration-form-fields', eventId] })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useImportFieldsFromEvent(orgId: Ref<string>, eventId: Ref<string>) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: async (sourceEventId: string) => {
|
|
const { data } = await apiClient.post<ApiResponse<RegistrationFormField[]>>(
|
|
`/organisations/${orgId.value}/events/${eventId.value}/registration-fields/import-from-event`,
|
|
{ source_event_id: sourceEventId },
|
|
)
|
|
|
|
return data.data
|
|
},
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: ['registration-form-fields', eventId] })
|
|
},
|
|
})
|
|
}
|