upd: profile
Deskripsi: - percobaan fetch profile menggunakan redux - install package redux No Issues
This commit is contained in:
10
lib/api.ts
10
lib/api.ts
@@ -9,16 +9,16 @@ export const apiCheckPhoneLogin = async (body: { phone: string }) => {
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export const apiSendOtp = async (body: { phone: string, otp:number }) => {
|
||||
export const apiSendOtp = async (body: { phone: string, otp: number }) => {
|
||||
const res = await axios.get(`https://wa.wibudev.com/code?nom=${body.phone}&text=*DARMASABA*%0A%0A
|
||||
JANGAN BERIKAN KODE RAHASIA ini kepada siapa pun TERMASUK PIHAK DARMASABA. Masukkan otentikasi: *${encodeURIComponent(body.otp)}*`)
|
||||
return res.status
|
||||
}
|
||||
|
||||
// export const getEntities = async () => {
|
||||
// const response = await axios.get('https://stg-darmasaba.wibudev.com/api/version-app');
|
||||
// return response.data;
|
||||
// };
|
||||
export const apiGetProfile = async ({ id }: { id: string }) => {
|
||||
const response = await api.get(`/user/${id}`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
// export const createEntity = async (newEntity: any) => {
|
||||
// const response = await api.post('/entities', newEntity);
|
||||
|
||||
29
lib/entitiesSlice.ts
Normal file
29
lib/entitiesSlice.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { createSlice } from '@reduxjs/toolkit';
|
||||
|
||||
const entitiesSlice = createSlice({
|
||||
name: 'entities',
|
||||
initialState: {},
|
||||
reducers: {
|
||||
setEntities: (state, action) => {
|
||||
return action.payload;
|
||||
},
|
||||
|
||||
addEntity: (state: any, action: any) => {
|
||||
state.push(action.payload);
|
||||
},
|
||||
updateEntity: (state: any, action) => {
|
||||
const { id, updatedEntity } = action.payload;
|
||||
const index = state.findIndex((entity: any) => entity.id === id);
|
||||
if (index !== -1) {
|
||||
state[index] = updatedEntity;
|
||||
}
|
||||
},
|
||||
// removeEntity: (state, action) => {
|
||||
// const idToRemove = action.payload;
|
||||
// return state.filter((entity: any) => entity.id !== idToRemove);
|
||||
// },
|
||||
},
|
||||
});
|
||||
|
||||
export const { setEntities, addEntity, updateEntity } = entitiesSlice.actions;
|
||||
export default entitiesSlice.reducer;
|
||||
11
lib/store.ts
Normal file
11
lib/store.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { configureStore } from '@reduxjs/toolkit';
|
||||
import entitiesReducer from './entitiesSlice';
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
entities: entitiesReducer,
|
||||
// Add other reducers as needed
|
||||
},
|
||||
});
|
||||
|
||||
export default store;
|
||||
Reference in New Issue
Block a user