-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add authSlice and authService for
color, product, customer and enquiry
- Loading branch information
vit718
committed
Jul 13, 2023
1 parent
0b86362
commit dbcaedc
Showing
10 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import axios from "axios"; | ||
import { base_url } from "../../utils/base_url"; | ||
|
||
const getColors = async () => { | ||
const response = await axios.get(`${base_url}color/`); | ||
|
||
return response.data; | ||
}; | ||
|
||
const colorService = { | ||
getColors, | ||
}; | ||
|
||
export default colorService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; | ||
import colorService from "./colorService"; | ||
|
||
export const getColors = createAsyncThunk( | ||
"color/get-colors", | ||
async (thunkAPI) => { | ||
try { | ||
return await colorService.getColors(); | ||
} catch (error) { | ||
return thunkAPI.rejectWithValue(error); | ||
} | ||
} | ||
); | ||
|
||
const initialState = { | ||
colors: [], | ||
isError: false, | ||
isLoading: false, | ||
isSuccess: false, | ||
message: "", | ||
}; | ||
export const colorSlice = createSlice({ | ||
name: "colors", | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(getColors.pending, (state) => { | ||
state.isLoading = true; | ||
}) | ||
.addCase(getColors.fulfilled, (state, action) => { | ||
state.isLoading = false; | ||
state.isError = false; | ||
state.isSuccess = true; | ||
state.colors = action.payload; | ||
}) | ||
.addCase(getColors.rejected, (state, action) => { | ||
state.isLoading = false; | ||
state.isError = true; | ||
state.isSuccess = false; | ||
state.message = action.error; | ||
}); | ||
}, | ||
}); | ||
export default colorSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import axios from "axios"; | ||
import { base_url } from "../../utils/base_url"; | ||
|
||
const getUsers = async () => { | ||
const response = await axios.get(`${base_url}user/all-users`); | ||
return response.data; | ||
}; | ||
|
||
const customerService = { | ||
getUsers, | ||
}; | ||
|
||
export default customerService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; | ||
import customerService from "./customerService"; | ||
|
||
const initialState = { | ||
customers: [], | ||
isError: false, | ||
isLoading: false, | ||
isSuccess: false, | ||
message: "", | ||
}; | ||
|
||
export const getUsers = createAsyncThunk( | ||
"customer/get-customers", | ||
async (thunkAPI) => { | ||
try { | ||
return await customerService.getUsers(); | ||
} catch (error) { | ||
return thunkAPI.rejectWithValue(error); | ||
} | ||
} | ||
); | ||
|
||
export const customerSlice = createSlice({ | ||
name: "users", | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder.addCase(getUsers.pending, (state) => { | ||
state.isLoading = true; | ||
}); | ||
builder.addCase(getUsers.fulfilled, (state, action) => { | ||
state.isLoading = false; | ||
state.isSuccess = true; | ||
state.isError = false; | ||
state.customers = action.payload; | ||
}); | ||
builder.addCase(getUsers.rejected, (state, action) => { | ||
state.isLoading = false; | ||
state.isError = true; | ||
state.isSuccess = false; | ||
state.customers = null; | ||
state.message = action.error; | ||
}); | ||
}, | ||
}); | ||
|
||
export default customerSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import axios from "axios"; | ||
import { base_url } from "../../utils/base_url"; | ||
|
||
const getEnquiries = async () => { | ||
const response = await axios.get(`${base_url}enquiry/`); | ||
|
||
return response.data; | ||
}; | ||
|
||
const enquiryService = { | ||
getEnquiries, | ||
}; | ||
|
||
export default enquiryService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; | ||
import enquiryService from "./enquiryService"; | ||
|
||
export const getEnquiries = createAsyncThunk( | ||
"enquiry/get-enquiries", | ||
async (thunkAPI) => { | ||
try { | ||
return await enquiryService.getEnquiries(); | ||
} catch (error) { | ||
return thunkAPI.rejectWithValue(error); | ||
} | ||
} | ||
); | ||
|
||
const initialState = { | ||
enquiries: [], | ||
isError: false, | ||
isLoading: false, | ||
isSuccess: false, | ||
message: "", | ||
}; | ||
|
||
export const enquirySlice = createSlice({ | ||
name: "enquiries", | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(getEnquiries.pending, (state) => { | ||
state.isLoading = true; | ||
}) | ||
.addCase(getEnquiries.fulfilled, (state, action) => { | ||
state.isLoading = false; | ||
state.isError = false; | ||
state.isSuccess = true; | ||
state.enquiries = action.payload; | ||
}) | ||
.addCase(getEnquiries.rejected, (state, action) => { | ||
state.isLoading = false; | ||
state.isError = true; | ||
state.isSuccess = false; | ||
state.message = action.error; | ||
}); | ||
}, | ||
}); | ||
|
||
export default enquirySlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import axios from "axios"; | ||
import { base_url } from "../../utils/base_url"; | ||
|
||
const getProducts = async () => { | ||
const response = await axios.get(`${base_url}product/`); | ||
return response.data; | ||
}; | ||
|
||
const productService = { | ||
getProducts, | ||
}; | ||
|
||
export default productService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; | ||
import productService from "./productService"; | ||
|
||
const initialState = { | ||
products: [], | ||
isError: false, | ||
isLoading: false, | ||
isSuccess: false, | ||
message: "", | ||
}; | ||
|
||
export const getProducts = createAsyncThunk( | ||
"product/get-products", | ||
async (thunkAPI) => { | ||
try { | ||
return await productService.getProducts(); | ||
} catch (error) { | ||
return thunkAPI.rejectWithValue(error); | ||
} | ||
} | ||
); | ||
|
||
export const productSlice = createSlice({ | ||
name: "products", | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder.addCase(getProducts.pending, (state) => { | ||
state.isLoading = true; | ||
}); | ||
builder.addCase(getProducts.fulfilled, (state, action) => { | ||
state.isLoading = false; | ||
state.isSuccess = true; | ||
state.isError = false; | ||
state.products = action.payload; | ||
}); | ||
builder.addCase(getProducts.rejected, (state, action) => { | ||
state.isLoading = false; | ||
state.isError = true; | ||
state.isSuccess = false; | ||
state.products = null; | ||
state.message = action.error; | ||
}); | ||
}, | ||
}); | ||
|
||
export default productSlice.reducer; |
13 changes: 13 additions & 0 deletions
13
admin-dashboard/src/features/productCategory/productCategoryService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import axios from "axios"; | ||
import { base_url } from "../../utils/base_url"; | ||
|
||
const getProductCategories = async () => { | ||
const response = await axios.get(`${base_url}product-category/`); | ||
return response.data; | ||
}; | ||
|
||
const productCategoryService = { | ||
getProductCategories, | ||
}; | ||
|
||
export default productCategoryService; |
47 changes: 47 additions & 0 deletions
47
admin-dashboard/src/features/productCategory/productCategorySlice.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; | ||
import productCategoryService from "./productCategoryService"; | ||
|
||
const initialState = { | ||
productCategories: [], | ||
isError: false, | ||
isLoading: false, | ||
isSuccess: false, | ||
message: "", | ||
}; | ||
|
||
export const getCategories = createAsyncThunk( | ||
"productCategory/get-categories", | ||
async (thunkAPI) => { | ||
try { | ||
return await productCategoryService.getProductCategories(); | ||
} catch (error) { | ||
return thunkAPI.rejectWithValue(error); | ||
} | ||
} | ||
); | ||
|
||
export const productCategorySlice = createSlice({ | ||
name: "productCategories", | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder.addCase(getCategories.pending, (state) => { | ||
state.isLoading = true; | ||
}); | ||
builder.addCase(getCategories.fulfilled, (state, action) => { | ||
state.isLoading = false; | ||
state.isSuccess = true; | ||
state.isError = false; | ||
state.productCategories = action.payload; | ||
}); | ||
builder.addCase(getCategories.rejected, (state, action) => { | ||
state.isLoading = false; | ||
state.isError = true; | ||
state.isSuccess = false; | ||
state.productCategories = null; | ||
state.message = action.error; | ||
}); | ||
}, | ||
}); | ||
|
||
export default productCategorySlice.reducer; |