Skip to content

Commit

Permalink
update admin
Browse files Browse the repository at this point in the history
  • Loading branch information
HoaAyWK committed Nov 16, 2022
1 parent a3ec29f commit 0a6b61f
Show file tree
Hide file tree
Showing 37 changed files with 3,506 additions and 342 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
/.pnp
.pnp.js

/config

# testing
/coverage

Expand Down
1,865 changes: 1,728 additions & 137 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"axios": "^1.1.3",
"change-case": "^4.1.2",
"date-fns": "^2.29.3",
"firebase": "^9.14.0",
"js-cookie": "^3.0.1",
"lodash": "^4.17.21",
"notistack": "^2.0.8",
Expand All @@ -31,6 +32,7 @@
"react-router-dom": "^6.4.2",
"react-scripts": "5.0.1",
"simplebar-react": "^2.4.3",
"uuid": "^9.0.0",
"web-vitals": "^2.1.4",
"yup": "^0.32.11"
},
Expand Down
Binary file added public/static/illustrations/file-folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 15 additions & 9 deletions src/app/slices/authSlice.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import axios from 'axios';
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import { v4 as uuidv4 } from 'uuid';

import { BASE_API_URL, action_status, ROLES, MESSAGE_VARIANT, MESSAGE_ERRORS } from '../constants';
import { setMessage } from './messageSlice';
import api from '../api';
import { BASE_API_URL, action_status, MESSAGE_VARIANT } from '../constants';
import { setMessage } from './messageSlice';
import { uploadTaskPromise } from '../../utils/uploadTaskPromise';

const initialState = {
user: null,
Expand Down Expand Up @@ -54,8 +56,15 @@ export const updateAccount = createAsyncThunk(
'auth/updateAccount',
async (updateBody, thunkApi) => {
try {
const { email, ...dataToUpdate } = updateBody;
const { data } = await axios.put(`${BASE_API_URL}/profile`, dataToUpdate, { withCredentials: true});
const { email, image, address, city, country, ...dataToUpdate } = updateBody;
const filePath = `files/avatars/${uuidv4()}`;

if (image) {
dataToUpdate.image = await uploadTaskPromise(filePath, image);
};

dataToUpdate.address = address + ', ' + city + ', ' + country;
const { data } = await api.put(`/users/profile`, dataToUpdate);

return data;
} catch (error) {
Expand All @@ -78,11 +87,7 @@ export const changePassword = createAsyncThunk(
newPassword: updateBody.newPassword
};

const { data } = await axios.put(
`${BASE_API_URL}/password/change`,
passwords,
{ withCredentials: true }
);
const { data } = await api.put(`/account/changePassword`, passwords);

return data;
} catch (error) {
Expand Down Expand Up @@ -149,6 +154,7 @@ const authSlice = createSlice({
.addCase(updateAccount.fulfilled, (state, action) => {
state.updated = true;
state.updateStatus = action_status.SUCCEEDED;
state.user = action.payload.user;
})
.addCase(updateAccount.rejected, (state, action) => {
state.updateStatus = action_status.FAILED;
Expand Down
31 changes: 27 additions & 4 deletions src/app/slices/categorySlice.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { createSlice, createAsyncThunk, createEntityAdapter, createSelector } from '@reduxjs/toolkit';
import { v4 as uuidv4 } from 'uuid';

import { action_status, BASE_API_URL, MESSAGE_VARIANT } from '../constants';
import { setMessage } from './messageSlice';
import api from '../api';
import { action_status, MESSAGE_VARIANT } from '../constants';
import { setMessage } from './messageSlice';
import { uploadTaskPromise } from '../../utils/uploadTaskPromise';

const categoriesAdapter = createEntityAdapter();

const initialState = categoriesAdapter.getInitialState({
status: action_status.IDLE,
error: null,
addOrUpdateStatus: action_status.IDLE,
isUpdated: false,
isAdded: false,
isDeleted: false
Expand All @@ -26,7 +29,10 @@ export const createCategory = createAsyncThunk(
'categories/create',
async (category, thunkApi) => {
try {
const { data } = await api.post('/categories/admin/create', category);
const { name, image } = category;
const filePath = `files/categories/${uuidv4()}`;
const imageUrl = await uploadTaskPromise(filePath, image);
const { data } = await api.post('/categories/admin/create', { name, image: imageUrl });

return data;
} catch (error) {
Expand All @@ -44,7 +50,13 @@ export const updateCategory = createAsyncThunk(
'categories/update',
async (category, thunkApi) => {
try {
const { data } = await api.put(`/categories/admin/${category.id}`, category);
const { id, image, ...updateData } = category;
if (image) {
const filePath = `files/categories/${uuidv4()}`;
updateData.image = await uploadTaskPromise(filePath, image);
}

const { data } = await api.put(`/categories/admin/${id}`, updateData);

return data;
} catch (error) {
Expand Down Expand Up @@ -85,6 +97,7 @@ const categorySlice = createSlice({
state.isUpdated = false;
state.isAdded = false;
state.isDeleted = false;
state.addOrUpdateStatus = action_status.IDLE;
}
},
extraReducers: (builder) => {
Expand All @@ -100,18 +113,28 @@ const categorySlice = createSlice({
state.status = action_status.FAILED;
state.error = action.error;
})
.addCase(createCategory.pending, (state, action) => {
state.addOrUpdateStatus = action_status.LOADING;
})
.addCase(createCategory.fulfilled, (state, action) => {
categoriesAdapter.addOne(state, action.payload.category);
state.addOrUpdateStatus = action_status.SUCCEEDED;
state.isAdded = true;
})
.addCase(createCategory.rejected, (state, action) => {
state.error = action.error;
state.addOrUpdateStatus = action_status.FAILED;
})
.addCase(updateCategory.pending, (state, action) => {
state.addOrUpdateStatus = action_status.LOADING;
})
.addCase(updateCategory.fulfilled, (state, action) => {
state.isUpdated = true;
state.addOrUpdateStatus = action_status.SUCCEEDED;
})
.addCase(updateCategory.rejected, (state, action) => {
state.error = action.error;
state.addOrUpdateStatus = action_status.FAILED;
})
.addCase(deleteCategory.pending, (state, action) => {
state.isDeleted = false;
Expand Down
51 changes: 51 additions & 0 deletions src/app/slices/employerSlice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { createAsyncThunk, createSlice, createEntityAdapter } from "@reduxjs/toolkit";

import { action_status } from '../constants';
import api from '../api';

const employersAdaper = createEntityAdapter();

const initialState = employersAdaper.getInitialState({
status: action_status.IDLE,
error: null
});

export const getEmployers = createAsyncThunk(
'employers/getEmployers',
async () => {
const { data } = await api.get(`/employer`);

return data;
}
);

const employerslice = createSlice({
name: 'employers',
initialState,
reducers: {
},
extraReducers: (builder) => {
builder
.addCase(getEmployers.pending, (state, action) => {
state.status = action_status.LOADING;
})
.addCase(getEmployers.fulfilled, (state, action) => {
state.status = action_status.SUCCEEDED;
employersAdaper.setAll(state, action.payload.employers);
})
.addCase(getEmployers.rejected, (state, action) => {
state.status = action_status.FAILED;
state.error = action.error;
})
}
});

export const {
selectAll: selectAllEmployers,
selectById: selectEmpployerById,
selectIds: selectEmpployerIds
} = employersAdaper.getSelectors((state) => state.employers);

const { reducer } = employerslice;

export default reducer;
51 changes: 51 additions & 0 deletions src/app/slices/freelancerSlice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { createAsyncThunk, createSlice, createEntityAdapter } from "@reduxjs/toolkit";

import { action_status } from '../constants';
import api from '../api';

const freelancersAdaper = createEntityAdapter();

const initialState = freelancersAdaper.getInitialState({
status: action_status.IDLE,
error: null
});

export const getFreelancers = createAsyncThunk(
'freelancers/getFreelancers',
async () => {
const { data } = await api.get(`/freelancer`);

return data;
}
);

const freelancerslice = createSlice({
name: 'freelancers',
initialState,
reducers: {
},
extraReducers: (builder) => {
builder
.addCase(getFreelancers.pending, (state, action) => {
state.status = action_status.LOADING;
})
.addCase(getFreelancers.fulfilled, (state, action) => {
state.status = action_status.SUCCEEDED;
freelancersAdaper.setAll(state, action.payload.freelancers);
})
.addCase(getFreelancers.rejected, (state, action) => {
state.status = action_status.FAILED;
state.error = action.error;
})
}
});

export const {
selectAll: selectAllFreelancers,
selectById: selectFreelancerById,
selectIds: selectFreelancerIds
} = freelancersAdaper.getSelectors((state) => state.freelancers);

const { reducer } = freelancerslice;

export default reducer;
29 changes: 23 additions & 6 deletions src/app/slices/packagesSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const packagesAdapter = createEntityAdapter();
const initialState = packagesAdapter.getInitialState({
error: null,
status: action_status.IDLE,
addOrUpdateStatus: action_status.IDLE,
isAdded: false,
isUpdated: false,
isDeleted: false
Expand All @@ -23,7 +24,7 @@ export const getPackages = createAsyncThunk(
}
);

export const createPackages = createAsyncThunk(
export const createPackage = createAsyncThunk(
'packages/create',
async (pkg, thunkApi) => {
try {
Expand All @@ -45,7 +46,8 @@ export const updatePackage = createAsyncThunk(
'packages/update',
async (pkg, thunkApi) => {
try {
const { data } = await api.put(`$/packages/admin/${pkg.id}`, pkg);
const { id, ...pkgData } = pkg;
const { data } = await api.put(`/packages/admin/${id}`, pkgData);

return data;
} catch (error) {
Expand All @@ -63,7 +65,7 @@ export const deletePackage = createAsyncThunk(
'packages/delete',
async (id, thunkApi) => {
try {
const { data } = await axios.delete(`$/packages/admin/${id}`);
const { data } = await api.delete(`/packages/admin/${id}`);

data.id = id;

Expand All @@ -77,7 +79,7 @@ export const deletePackage = createAsyncThunk(
return thunkApi.rejectWithValue();
}
}
)
);

const packagesSlice = createSlice({
name: 'packages',
Expand All @@ -87,6 +89,7 @@ const packagesSlice = createSlice({
state.isAdded = false;
state.isUpdated = false;
state.isDeleted = false;
state.addOrUpdateStatus = action_status.IDLE;
}
},
extraReducers: (builder) => {
Expand All @@ -102,13 +105,27 @@ const packagesSlice = createSlice({
state.status = action_status.FAILED;
state.error = action.error;
})
.addCase(createPackages.pending, (state, action) => {
.addCase(createPackage.pending, (state, action) => {
state.isAdded = false;
state.addOrUpdateStatus = action_status.LOADING;
})
.addCase(createPackages.fulfilled, (state, action) => {
.addCase(createPackage.fulfilled, (state, action) => {
packagesAdapter.addOne(state, action.payload.package);
state.addOrUpdateStatus = action_status.SUCCEEDED;
state.isAdded = true;
})
.addCase(updatePackage.pending, (state, action) => {
state.addOrUpdateStatus = action_status.LOADING;
state.isUpdated = false;
})
.addCase(updatePackage.fulfilled, (state, action) => {
state.addOrUpdateStatus = action_status.SUCCEEDED;
state.isUpdated = true;
})
.addCase(updatePackage.rejected, (state, action) => {
state.addOrUpdateStatus = action_status.FAILED;
state.isUpdated = false;
})
.addCase(deletePackage.pending, (state, action) => {
state.isDeleted = false;
})
Expand Down
6 changes: 3 additions & 3 deletions src/app/slices/statisticSlice.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";

import { action_status, BASE_API_URL } from "../constants";
import api from '../api';
import { action_status } from "../constants";

const initialState = {
statistic: [],
Expand All @@ -13,7 +13,7 @@ const initialState = {
export const getStatistic = createAsyncThunk(
'statistic/getStatistic',
async () => {
const { data } = await axios.get(`${BASE_API_URL}/pointhistories/statistic`);
const { data } = await api.get(`/transactions/stats`);

return data;
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import commentReducer from './slices/commentSlice';
import offerReducer from './slices/offerSlice';
import transactionReducer from './slices/transactionSlice';
import skillReducer from './slices/skillSlice';
import freelancerReducer from './slices/freelancerSlice';
import employerReducer from './slices/employerSlice';

export const store = configureStore({
reducer: {
Expand All @@ -27,6 +29,8 @@ export const store = configureStore({
comments: commentReducer,
offers: offerReducer,
transactions: transactionReducer,
skills: skillReducer
skills: skillReducer,
freelancers: freelancerReducer,
employers: employerReducer
},
});
Loading

0 comments on commit 0a6b61f

Please sign in to comment.