41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { StorageServiceCasual } from 'common-ui'
|
|
|
|
/**
|
|
* A delivery address the user filled in while signed out. It is kept in local
|
|
* storage and posted to the backend once the user has an account (see
|
|
* PendingAddressSync). Coordinates are always present because they come from
|
|
* the map picker.
|
|
*/
|
|
export interface PendingAddressInput {
|
|
regionId: number
|
|
name: string
|
|
phone: string
|
|
addressLine1: string
|
|
addressLine2?: string
|
|
city: string
|
|
state: string
|
|
isDefault?: boolean
|
|
latitude: number
|
|
longitude: number
|
|
googleMapsUrl?: string
|
|
}
|
|
|
|
const PENDING_ADDRESS_KEY = 'freshyo_pending_address'
|
|
|
|
export async function savePendingAddress(address: PendingAddressInput): Promise<void> {
|
|
await StorageServiceCasual.setItem(PENDING_ADDRESS_KEY, JSON.stringify(address))
|
|
}
|
|
|
|
export async function getPendingAddress(): Promise<PendingAddressInput | null> {
|
|
const raw = await StorageServiceCasual.getItem(PENDING_ADDRESS_KEY)
|
|
if (!raw) return null
|
|
try {
|
|
return JSON.parse(raw) as PendingAddressInput
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export async function clearPendingAddress(): Promise<void> {
|
|
await StorageServiceCasual.removeItem(PENDING_ADDRESS_KEY)
|
|
}
|