import { createReducer, createAction } from '@reduxjs/toolkit'; // ─── Actions ────────────────────────────────────────────────────────────────── export const setLocationData = createAction<{ latitude: number; longitude: number; mapAddress: string; }>('setLocation/setLocationData'); export const clearLocationData = createAction('setLocation/clearLocationData'); // ─── State ──────────────────────────────────────────────────────────────────── export interface SetLocationState { latitude: number | null; longitude: number | null; mapAddress: string; } const initialState: SetLocationState = { latitude: null, longitude: null, mapAddress: '', }; // ─── 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; }) .addCase(clearLocationData, state => { state.latitude = null; state.longitude = null; state.mapAddress = ''; }); }); export default setLocationReducer;