import { createReducer, createAction } from '@reduxjs/toolkit'; // ─── Actions ────────────────────────────────────────────────────────────────── export const setLocationData = createAction<{ latitude: number; longitude: number; mapAddress: string; city: string; state: string; postalCode: string; }>('setLocation/setLocationData'); export const clearLocationData = createAction('setLocation/clearLocationData'); // ─── State ──────────────────────────────────────────────────────────────────── export interface SetLocationState { latitude: number | null; longitude: number | null; mapAddress: string; city: string; state: string; postalCode: string; } const initialState: SetLocationState = { latitude: null, longitude: null, mapAddress: '', city: '', state: '', postalCode: '', }; // ─── Reducer ────────────────────────────────────────────────────────────────── const setLocationReducer = createReducer(initialState, builder => { builder .addCase(setLocationData, (state, action) => { state.latitude = action.payload.latitude; state.longitude = action.payload.longitude; state.mapAddress = action.payload.mapAddress; state.city = action.payload.city; state.state = action.payload.state; state.postalCode = action.payload.postalCode; }) .addCase(clearLocationData, state => { state.latitude = null; state.longitude = null; state.mapAddress = ''; state.city = ''; state.state = ''; state.postalCode = ''; }); }); export default setLocationReducer;