gigafibre-fsm/apps/client/src/composables/useAddressSearch.js
louispaulb 320655b0a0 refactor: major cleanup — remove dead dispatch app, commit all backend code, extract client composables
- Remove apps/dispatch/ (100% replaced by ops dispatch module, unmaintained)
- Commit services/targo-hub/lib/ (24 modules, 6290 lines — was never tracked)
- Commit services/docuseal + services/legacy-db docker-compose configs
- Extract client app composables: useOTP, useAddressSearch, catalog data, format utils
- Refactor CartPage.vue 630→175 lines, CatalogPage.vue 375→95 lines
- Clean hardcoded credentials from config.js fallback values
- Add client portal: catalog, cart, checkout, OTP verification, address search
- Add ops: NetworkPage, AgentFlowsPage, ConversationPanel, UnifiedCreateModal
- Add ops composables: useBestTech, useConversations, usePermissions, useScanner
- Add field app: scanner composable, docker/nginx configs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 17:38:38 -04:00

50 lines
1.6 KiB
JavaScript

import { ref, onUnmounted } from 'vue'
import { searchAddresses } from 'src/api/catalog'
export function useAddressSearch (form) {
const query = ref('')
const results = ref([])
const searching = ref(false)
const selected = ref(false)
let debounce = null
function onInput (val) {
selected.value = false
Object.assign(form, { address: '', city: '', postalCode: '', latitude: null, longitude: null })
if (debounce) clearTimeout(debounce)
if (!val || val.length < 3) { results.value = []; return }
debounce = setTimeout(async () => {
searching.value = true
try { results.value = await searchAddresses(val) }
catch { results.value = [] }
finally { searching.value = false }
}, 300)
}
function selectResult (a) {
Object.assign(form, {
address: a.adresse_formatee || '', city: a.nom_municipalite || '',
postalCode: a.code_postal || '', latitude: a.latitude || null,
longitude: a.longitude || null, province: 'QC',
})
query.value = a.adresse_formatee || ''
results.value = []
selected.value = true
}
function selectCustomerAddr (addr) {
Object.assign(form, {
address: addr.address || '', city: addr.city || '',
postalCode: addr.postal_code || '', latitude: addr.latitude || null,
longitude: addr.longitude || null, province: 'QC',
})
query.value = addr.address || ''
selected.value = true
results.value = []
}
onUnmounted(() => { if (debounce) clearTimeout(debounce) })
return { query, results, searching, selected, onInput, selectResult, selectCustomerAddr }
}