Skip to content

Commit

Permalink
feat: add authSlice and authService for
Browse files Browse the repository at this point in the history
color, product, customer and enquiry
  • Loading branch information
vit718 committed Jul 13, 2023
1 parent 0b86362 commit dbcaedc
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 0 deletions.
14 changes: 14 additions & 0 deletions admin-dashboard/src/features/color/colorService.js
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;
45 changes: 45 additions & 0 deletions admin-dashboard/src/features/color/colorSlice.js
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;
13 changes: 13 additions & 0 deletions admin-dashboard/src/features/customers/customerService.js
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;
47 changes: 47 additions & 0 deletions admin-dashboard/src/features/customers/customerSlice.js
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;
14 changes: 14 additions & 0 deletions admin-dashboard/src/features/enquiry/enquiryService.js
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;
47 changes: 47 additions & 0 deletions admin-dashboard/src/features/enquiry/enquirySlice.js
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;
13 changes: 13 additions & 0 deletions admin-dashboard/src/features/product/productService.js
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;
47 changes: 47 additions & 0 deletions admin-dashboard/src/features/product/productSlice.js
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;
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;
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;

0 comments on commit dbcaedc

Please sign in to comment.