Documentation
/
Examples
Examples
v0.00
TypeScript
Real-world examples of using wappi-fe in different scenarios and frameworks.
1
2 useEffect(() => {
3 if (!user) return; // Wait until the user object is available
4 const authenticateUser = async () => {
5 try {
6 await request(WAPPI_CONFIG, {
7 name: 'Core Login',
8 query: 'Core_Login_2_0_0',
9 data: { userAuth0Sub: user.sub },
10 successCallback: (x) => {
11 localStorage.removeItem('loginRedirectUrl')
12 reduxDispatch(saveUserAndEnterDashboard(x as UserState));
13 router.push(forwardToPath);
14 },
15 errorCallback: () => {
16 toast({
17 title: 'Error',
18 description: 'We had trouble logging you in. Try again.',
19 status: 'error',
20 duration: 9000,
21 isClosable: true,
22 });
23 },
24 });
25 } catch (error) {
26 console.error(error);
27 }
28 };
29
30 authenticateUser();
31 }, [user, reduxDispatch, toast]);
32
33This allows you to create a /API folder and have a lot of reusable calls to your backend.
1import { request } from 'wappi-fe';
2import { WAPPI_CONFIG } from './wappiConfig';
3
4export const getAllProducts = async () => request(WAPPI_CONFIG, {
5 name: 'Get Products',
6 query: 'Products_GetAllProducts_3_2_12',
7 data: {},
8 authRequired: false,
9 errorCallback: (e) => console.error(e.message),
10});
111import { request } from 'wappi-fe';
2import { WAPPI_CONFIG } from './wappiConfig';
3import { User_UpdateUserDetails_2_4_9__Body } from './wappiTypes';
4
5export const updateUserDetails = async (
6 body: User_UpdateUserDetails_2_4_9__Body
7) => request(WAPPI_CONFIG, {
8 name: `Update ${body.userID} Details`,
9 query: 'User_UpdateUserDetails_2_4_9',
10 data: body,
11 authRequired: true,
12 errorCallback: (e) => console.error(e.message),
13});
14
15export const getUserDetails = async (
16 reason: string
17) => request(WAPPI_CONFIG, {
18 // Uniqueness helps with observability. Ex: Showing user 456 for client 123 on listPage
19 name: reason,
20 query: 'User_GetUserDetails_1_0_0',
21 data: {},
22 authRequired: true,
23 errorCallback: (e) => console.error(e.message),
24});
25