Skip to content

Commit

Permalink
update all
Browse files Browse the repository at this point in the history
  • Loading branch information
HoaAyWK committed Nov 17, 2022
1 parent 0a6b61f commit bc3ce38
Show file tree
Hide file tree
Showing 24 changed files with 1,250 additions and 729 deletions.
54 changes: 54 additions & 0 deletions src/app/slices/appliedSlice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';

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

const initialState = {
applieds: [],
status: action_status.IDLE,
error: null
};

export const getAppliedsByJob = createAsyncThunk(
'applieds/getAppliedsByJob',
async (jobId, thunkApi) => {
try {
const { data } = await api.get(`/applied/admin/${jobId}`);

return data;
} catch (error) {
const message = (error.response && error.response.data && error.response.data.message)
|| error.message || error.toString();

thunkApi.dispatch(setMessage({ message, variant: MESSAGE_VARIANT.ERROR }));

return thunkApi.rejectWithValue();
}
}
);

const appliedslice = createSlice({
name: 'applieds',
initialState,
reducers: {
},
extraReducers: (builder) => {
builder
.addCase(getAppliedsByJob.pending, (state, action) => {
state.status = action_status.LOADING;
})
.addCase(getAppliedsByJob.fulfilled, (state, action) => {
state.status = action_status.SUCCEEDED;
state.applieds = action.payload.applieds;
})
.addCase(getAppliedsByJob.rejected, (state, action) => {
state.status = action_status.FAILED;
state.error = action.error;
})
}
});

const { reducer } = appliedslice;

export default reducer;
4 changes: 2 additions & 2 deletions src/app/slices/employerSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const employerslice = createSlice({

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

const { reducer } = employerslice;
Expand Down
7 changes: 4 additions & 3 deletions src/app/slices/jobSlice.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios from 'axios';
import { createSlice, createAsyncThunk, createEntityAdapter, createSelector } from "@reduxjs/toolkit";

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

const jobsAdapter = createEntityAdapter();

Expand All @@ -13,7 +14,7 @@ const initialState = jobsAdapter.getInitialState({
export const getJobs = createAsyncThunk(
'jobs/getJobs',
async () => {
const { data } = await axios.get(`${BASE_API_URL}/admin/jobs`, { withCredentials: true });
const { data } = await api.get(`/job/show`);

return data;
}
Expand Down Expand Up @@ -49,7 +50,7 @@ export const {

export const selectJobsByUser = createSelector(
[selectAllJobs, (state, userId) => userId],
(jobs, userId) => jobs.filter(job => job.owner.id === userId)
(jobs, userId) => jobs.filter(job => job.employer.id === userId)
);

const { reducer } = jobSlice;
Expand Down
2 changes: 1 addition & 1 deletion src/app/slices/statisticSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const initialState = {
export const getStatistic = createAsyncThunk(
'statistic/getStatistic',
async () => {
const { data } = await api.get(`/transactions/stats`);
const { data } = await api.get(`/stats`);

return data;
}
Expand Down
42 changes: 6 additions & 36 deletions src/app/slices/transactionSlice.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,28 @@
import { createSlice, createEntityAdapter, createAsyncThunk } from '@reduxjs/toolkit';
import axios from 'axios';

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

const transactionsAdapter = createEntityAdapter();

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

export const getTransactions = createAsyncThunk(
'transactions/getTransactions',
async () => {
const { data } = await axios.get(`${BASE_API_URL}/admin/transactions/all`, { withCredentials: true });
const { data } = await api.get(`/transactions`);
return data;
}
);

export const updateTransaction = createAsyncThunk(
'transactions/update',
async (id, thunkApi) => {
try {
const { data } = await axios.put(`${BASE_API_URL}/admin/transactions/${id}`, '',{ withCredentials: true });

return data;
} catch (error) {
const message = (error.response && error.response.data && error.response.data.message)
|| error.message || error.toString();

thunkApi.dispatch(setMessage({ message, variant: MESSAGE_VARIANT.ERROR }));

return thunkApi.rejectWithValue();
}
}
)

const transactionSlice = createSlice({
name: 'transactions',
initialState,
reducers: {
refresh: (state, action) => {
state.isUpdated = false;
}
},
extraReducers: (builder) => {
builder
Expand All @@ -59,24 +36,17 @@ const transactionSlice = createSlice({
.addCase(getTransactions.rejected, (state, action) => {
state.status = action_status.FAILED;
state.error = action.error;
})
.addCase(updateTransaction.pending, (state, action) => {
state.isUpdated = false;
})
.addCase(updateTransaction.fulfilled, (state, action) => {
state.isUpdated = true;
})
});
}
});

const { reducer, actions } = transactionSlice;
const { reducer } = transactionSlice;

export const {
selectAll: selectAllTransactions,
selectById: selectTransactionById,
selectIds: selectTransactionIds
} = transactionsAdapter.getSelectors((state) => state.transactions);

export const { refresh } = actions;

export default reducer;
4 changes: 3 additions & 1 deletion src/app/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import transactionReducer from './slices/transactionSlice';
import skillReducer from './slices/skillSlice';
import freelancerReducer from './slices/freelancerSlice';
import employerReducer from './slices/employerSlice';
import appliedReducer from './slices/appliedSlice';

export const store = configureStore({
reducer: {
Expand All @@ -31,6 +32,7 @@ export const store = configureStore({
transactions: transactionReducer,
skills: skillReducer,
freelancers: freelancerReducer,
employers: employerReducer
employers: employerReducer,
applieds: appliedReducer
},
});
125 changes: 0 additions & 125 deletions src/components/chart/EarningChart.jsx

This file was deleted.

Loading

0 comments on commit bc3ce38

Please sign in to comment.