turkmen-expo/redux/slices/aboutus.ts

52 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-10-12 17:42:17 +00:00
import { baseAPI } from "@/lib/API";
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
export const fetchAbout = createAsyncThunk(
"about/fetchAbout",
async ({ locale }: { locale: string }) => {
2025-10-12 17:42:17 +00:00
const res = await fetch(`${baseAPI}settings/about_us`, {
headers: {
"Accept-Language": locale,
2025-10-12 17:42:17 +00:00
},
});
const data = await res.json();
return data;
}
);
interface AboutType {
aboutData: string;
}
const initialState: AboutType = {
aboutData: "",
};
const aboutSlice = createSlice({
name: "aboutUs",
initialState,
reducers: {
setAboutUsData(state, action) {
state.aboutData = action.payload;
},
},
extraReducers: (builder) => {
builder.addCase(fetchAbout.pending, (state) => {});
2025-10-12 17:42:17 +00:00
builder.addCase(fetchAbout.fulfilled, (state, action) => {
state.aboutData = action.payload;
});
builder.addCase(fetchAbout.rejected, (state) => {
console.log("error");
});
},
});
export const { setAboutUsData } = aboutSlice.actions;
export default aboutSlice.reducer;