Axios API Calls

Mock API calls

Mock Calls

Mantis uses fack/mock data to render some pages and actions. Mocking has been achieved with help of Axios. It helps users to do minimal changes to load live data. Users just need to change the mock API URL to the Live service URL.

How does it work?

Axios have been configured in the folder ..src\utils\axios.js

To use Axios on a page, you need to import it and make a call. It is used from slices here: src\store\reducers. You need to call slice action from your page like below:

src\pages\apps\chat.js
...
import { getUser } from 'store/reducers/chat';
...

const Chat = () => {
      const chatState = useSelector((state) => state.chat);
      ...    
      useEffect(() => {
        setUser(chatState.user);
      }, [chatState.user]);
      ...
      ...  
      useEffect(() => {
        // hide left drawer when email app opens
        ...
        dispatch(getUser(1));
        // eslint-disable-next-line react-hooks/exhaustive-deps
      }, []);
    
    ...
    ...
    
 }

export default Chat;

Mantis has all dummy data in the folder src\data. For API, api/chat/users, following data configured in ..\src\data\chat.js :

\chat\index.js
...

export const users = [
    {
        id: 1,
        name: 'Alene',
        company: 'ABC Pvt Ltd',
        role: 'Sr. Customer Manager',
        work_email: 'alene_work@company.com',
        personal_email: 'alene@company.com',
        work_phone: '380-293-0177',
        personal_phone: '380-293-0177',
        location: 'Port Narciso',
        avatar: 'avatar-1.png',
        status: 'Laboris non ad et',
        lastMessage: '2h ago',
        birthdayText: 'happy Birthday Alene',
        unReadChatCount: 2,
        online_status: 'available'
    },
    {
        id: 2,
        name: 'Keefe',
        company: 'ABC Pvt Ltd',
        role: 'Dynamic Operations Officer',
        work_email: 'keefe_work@gmil.com',
        personal_email: 'keefe@gmil.com',
        work_phone: '253-418-5940',
        personal_phone: '253-418-5940',
        location: 'Afghanistan',
        avatar: 'avatar-2.png',
        status: 'Laboris non ad et',
        lastMessage: '1:20 AM',
        birthdayText: 'happy Birthday Keefe',
        unReadChatCount: 3,
        online_status: 'available'
    }
    ...
    ...
];
...
...
];
...
...
});

You can configure the same for postmethods as well.

Next JS

Next js has a different mechanism to handle API. We have created src/pages/api folder where all the API stays. Whenever a request happened to API, this will be called. for more about API in nextJS, please refer: https://nextjs.org/docs/api-routes/introduction

Last updated