Refactor preferred time format actions and slice for improved type safety and consistency; update action payloads to include data structure.
This commit is contained in:
@@ -49,12 +49,12 @@ export type SetPreferredTimeFormatActionType = IRequestSetPreferredTimeFormat |
|
|||||||
|
|
||||||
interface IGetPreferredTimeFormatActions {
|
interface IGetPreferredTimeFormatActions {
|
||||||
request: () => GetPreferredTimeFormatActionType;
|
request: () => GetPreferredTimeFormatActionType;
|
||||||
receive: (payload) => GetPreferredTimeFormatActionType;
|
receive: (payload: {data: TimeFormats}) => GetPreferredTimeFormatActionType;
|
||||||
failed: (error: null | string) => GetPreferredTimeFormatActionType;
|
failed: (error: null | string) => GetPreferredTimeFormatActionType;
|
||||||
}
|
}
|
||||||
interface ISetPreferredTimeFormatActions {
|
interface ISetPreferredTimeFormatActions {
|
||||||
request: () => SetPreferredTimeFormatActionType;
|
request: () => SetPreferredTimeFormatActionType;
|
||||||
receive: (payload) => SetPreferredTimeFormatActionType;
|
receive: (payload: {data: TimeFormats}) => SetPreferredTimeFormatActionType;
|
||||||
failed: (error: null | string) => SetPreferredTimeFormatActionType;
|
failed: (error: null | string) => SetPreferredTimeFormatActionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,12 +74,10 @@ const getPreferredTimeFormatActions: IGetPreferredTimeFormatActions = {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPreferredTimeFormat = () => async(dispatch: Dispatch<GetPreferredTimeFormatActionType>): Promise<void> => {
|
export const getPreferredTimeFormat =
|
||||||
const {
|
() =>
|
||||||
request,
|
async (dispatch: Dispatch<GetPreferredTimeFormatActionType>): Promise<void> => {
|
||||||
receive,
|
const {request, receive, failed} = getPreferredTimeFormatActions;
|
||||||
failed
|
|
||||||
} = getPreferredTimeFormatActions;
|
|
||||||
|
|
||||||
dispatch(request());
|
dispatch(request());
|
||||||
|
|
||||||
@@ -91,7 +89,7 @@ export const getPreferredTimeFormat = () => async(dispatch: Dispatch<GetPreferre
|
|||||||
preferredTimeFormat = await userStore.get('timeFormat');
|
preferredTimeFormat = await userStore.get('timeFormat');
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(receive({data: preferredTimeFormat}));
|
dispatch(receive({data: preferredTimeFormat as TimeFormats}));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const {message} = transformToPortalError(e);
|
const {message} = transformToPortalError(e);
|
||||||
|
|
||||||
@@ -111,12 +109,10 @@ const setPreferredTimeFormatActions: ISetPreferredTimeFormatActions = {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setPreferredTimeFormat = (format: TimeFormats) => async(dispatch: Dispatch<SetPreferredTimeFormatActionType>): Promise<void> => {
|
export const setPreferredTimeFormat =
|
||||||
const {
|
(format: TimeFormats) =>
|
||||||
request,
|
async (dispatch: Dispatch<SetPreferredTimeFormatActionType>): Promise<void> => {
|
||||||
receive,
|
const {request, receive, failed} = setPreferredTimeFormatActions;
|
||||||
failed
|
|
||||||
} = setPreferredTimeFormatActions;
|
|
||||||
|
|
||||||
dispatch(request());
|
dispatch(request());
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
import {createSlice, PayloadAction} from '@reduxjs/toolkit';
|
||||||
import { TimeFormats } from "utility";
|
import {TimeFormats} from 'utility';
|
||||||
|
|
||||||
export interface IPreferredTimeFormatState {
|
export interface IPreferredTimeFormatState {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
@@ -11,7 +11,7 @@ export const initialPreferredTimeFormatState: IPreferredTimeFormatState = {
|
|||||||
isLoading: false,
|
isLoading: false,
|
||||||
error: null,
|
error: null,
|
||||||
timeFormat: TimeFormats.Utc
|
timeFormat: TimeFormats.Utc
|
||||||
}
|
};
|
||||||
|
|
||||||
export const preferredTimeFormatSlice = createSlice({
|
export const preferredTimeFormatSlice = createSlice({
|
||||||
name: 'preferredTimeFormat',
|
name: 'preferredTimeFormat',
|
||||||
@@ -21,7 +21,7 @@ export const preferredTimeFormatSlice = createSlice({
|
|||||||
state.timeFormat = action.payload;
|
state.timeFormat = action.payload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
export const {setPreferredTimeFormat} = preferredTimeFormatSlice.actions;
|
export const {setPreferredTimeFormat} = preferredTimeFormatSlice.actions;
|
||||||
export default preferredTimeFormatSlice.reducer;
|
export default preferredTimeFormatSlice.reducer;
|
||||||
Reference in New Issue
Block a user