Initial commit from monorepo

This commit is contained in:
Ruslan Bakiev
2026-01-07 09:10:35 +07:00
commit 3db50d9637
371 changed files with 43223 additions and 0 deletions

119
app/stores/location.ts Normal file
View File

@@ -0,0 +1,119 @@
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { useGraphQL } from '~/composables/useGraphQL'
import { GetNodesDocument } from '~/composables/graphql/public/geo-generated'
interface SelectedLocation {
type: 'address' | 'hub'
uuid: string
name: string
latitude: number
longitude: number
}
export const useLocationStore = defineStore('location', () => {
const { mutate } = useGraphQL()
const selectedLocation = ref<SelectedLocation | null>(null)
const isLoading = ref(false)
const hasLocation = computed(() => !!selectedLocation.value)
const locationName = computed(() => selectedLocation.value?.name || '')
const locationType = computed(() => selectedLocation.value?.type || null)
async function fetch() {
isLoading.value = true
try {
const { GetTeamDocument } = await import('~/composables/graphql/team/teams-generated')
const { data: teamData, error: teamError } = await useServerQuery('location-team', GetTeamDocument, {}, 'team', 'teams')
if (teamError.value) throw teamError.value
const team = teamData.value?.team
if (team?.selectedLocation?.type && team?.selectedLocation?.uuid) {
const { type, uuid } = team.selectedLocation
if (type === 'hub') {
const { data: nodesData, error: nodesError } = await useServerQuery('location-nodes', GetNodesDocument, {}, 'public', 'geo')
if (nodesError.value) throw nodesError.value
const hub = nodesData.value?.nodes?.find((n: { uuid: string }) => n.uuid === uuid)
if (hub) {
selectedLocation.value = {
type: 'hub',
uuid: hub.uuid,
name: hub.name,
latitude: hub.latitude,
longitude: hub.longitude
}
}
} else if (type === 'address') {
const { GetTeamAddressesDocument } = await import('~/composables/graphql/team/teams-generated')
const { data: addressesData, error: addressesError } = await useServerQuery('location-addresses', GetTeamAddressesDocument, {}, 'team', 'teams')
if (addressesError.value) throw addressesError.value
const address = addressesData.value?.teamAddresses?.find((a: { uuid: string }) => a.uuid === uuid)
if (address) {
selectedLocation.value = {
type: 'address',
uuid: address.uuid,
name: address.name,
latitude: address.latitude,
longitude: address.longitude
}
}
}
}
} finally {
isLoading.value = false
}
}
async function select(type: 'address' | 'hub', uuid: string, name: string, latitude: number, longitude: number) {
console.log('[locationStore.select] called', { type, uuid, name, latitude, longitude })
isLoading.value = true
try {
const { SetSelectedLocationDocument } = await import('~/composables/graphql/team/teams-generated')
console.log('[locationStore.select] calling mutate')
const result = await mutate(SetSelectedLocationDocument, { input: { type, uuid, name, latitude, longitude } }, 'team', 'teams')
console.log('[locationStore.select] result:', result)
if (result?.setSelectedLocation?.success) {
selectedLocation.value = { type, uuid, name, latitude, longitude }
return true
}
console.error('[locationStore.select] success=false or missing', result)
return false
} catch (e) {
console.error('[locationStore.select] Error:', e)
return false
} finally {
isLoading.value = false
}
}
function setFromUserData(loc: { type: string; uuid: string; name: string; latitude: number; longitude: number } | null | undefined) {
if (loc?.type && loc?.uuid && loc?.name) {
selectedLocation.value = {
type: loc.type as 'address' | 'hub',
uuid: loc.uuid,
name: loc.name,
latitude: loc.latitude,
longitude: loc.longitude
}
}
}
function clear() {
selectedLocation.value = null
}
return {
selectedLocation,
isLoading,
hasLocation,
locationName,
locationType,
fetch,
select,
setFromUserData,
clear
}
})

96
app/stores/search.js Normal file
View File

@@ -0,0 +1,96 @@
import { defineStore } from 'pinia'
import { ref, computed, readonly } from 'vue'
export const useSearchStore = defineStore('search', () => {
// State for search form
const searchForm = ref({
product: '',
productUuid: '', // UUID for API
quantity: '',
unit: 'tons',
location: '',
locationUuid: '' // UUID for API
})
// State for created request
const currentRequest = ref(null)
// Getters
const isFormComplete = computed(() => {
return searchForm.value.product &&
searchForm.value.quantity &&
searchForm.value.location
})
const getSearchUrl = computed(() => {
if (!isFormComplete.value) return ''
const params = new URLSearchParams({
product: searchForm.value.product,
quantity: searchForm.value.quantity,
unit: searchForm.value.unit,
location: searchForm.value.location
})
return `/search?${params.toString()}`
})
// Actions
const setProduct = (product) => {
searchForm.value.product = product
}
const setProductUuid = (uuid) => {
searchForm.value.productUuid = uuid
}
const setLocation = (location) => {
searchForm.value.location = location
}
const setLocationUuid = (uuid) => {
searchForm.value.locationUuid = uuid
}
const setQuantity = (quantity) => {
searchForm.value.quantity = quantity
}
const setUnit = (unit) => {
searchForm.value.unit = unit
}
const setRequest = (request) => {
currentRequest.value = request
}
const resetForm = () => {
searchForm.value = {
product: '',
productUuid: '',
quantity: '',
unit: 'tons',
location: '',
locationUuid: ''
}
currentRequest.value = null
}
return {
// State
searchForm,
currentRequest,
// Getters
isFormComplete,
getSearchUrl,
// Actions
setProduct,
setProductUuid,
setLocation,
setLocationUuid,
setQuantity,
setUnit,
setRequest,
resetForm
}
})