feat: invite and reg

This commit is contained in:
zerosoul
2022-02-14 16:39:44 +08:00
parent 92d83e0dac
commit 6919b7404d
4 changed files with 338 additions and 86 deletions
+40 -33
View File
@@ -1,38 +1,45 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import baseQuery from "./base.query";
import BASE_URL, { ContentTypes } from "../config";
import { REHYDRATE } from "redux-persist";
import { createApi } from '@reduxjs/toolkit/query/react';
import baseQuery from './base.query';
import BASE_URL, { ContentTypes } from '../config';
import { REHYDRATE } from 'redux-persist';
export const contactApi = createApi({
reducerPath: "contact",
baseQuery,
extractRehydrationInfo(action, { reducerPath }) {
if (action.type === REHYDRATE) {
return action.payload ? action.payload[reducerPath] : undefined;
}
},
endpoints: (builder) => ({
getContacts: builder.query({
query: () => ({ url: `user` }),
transformResponse: (data) => {
return data.map((user) => {
const avatar = `${BASE_URL}/resource/avatar?uid=${user.uid}`;
user.avatar = avatar;
return user;
});
},
}),
sendMsg: builder.mutation({
query: ({ id, content, type = "text" }) => ({
headers: {
"content-type": ContentTypes[type],
},
url: `user/${id}/send`,
method: "POST",
body: content,
}),
}),
reducerPath: 'contact',
baseQuery,
extractRehydrationInfo(action, { reducerPath }) {
if (action.type === REHYDRATE) {
return action.payload ? action.payload[reducerPath] : undefined;
}
},
endpoints: (builder) => ({
getContacts: builder.query({
query: () => ({ url: `user` }),
transformResponse: (data) => {
return data.map((user) => {
const avatar = `${BASE_URL}/resource/avatar?uid=${user.uid}`;
user.avatar = avatar;
return user;
});
}
}),
register: builder.mutation({
query: (data) => ({
url: `user/register`,
method: 'POST',
body: data
})
}),
sendMsg: builder.mutation({
query: ({ id, content, type = 'text' }) => ({
headers: {
'content-type': ContentTypes[type]
},
url: `user/${id}/send`,
method: 'POST',
body: content
})
})
})
});
export const { useGetContactsQuery, useSendMsgMutation } = contactApi;
export const { useGetContactsQuery, useSendMsgMutation, useRegisterMutation } = contactApi;