mirror of
https://github.com/docmost/docmost.git
synced 2025-11-23 02:51:09 +10:00
implement new invitation system
* fix comments on the frontend * move jwt token service to its own module * other fixes and updates
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
import { useQuery, UseQueryResult } from "@tanstack/react-query";
|
||||
import { getUserInfo } from "@/features/user/services/user-service";
|
||||
import { getMyInfo } from "@/features/user/services/user-service";
|
||||
import { ICurrentUser } from "@/features/user/types/user.types";
|
||||
|
||||
export default function useCurrentUser(): UseQueryResult<ICurrentUser> {
|
||||
return useQuery({
|
||||
queryKey: ["currentUser"],
|
||||
queryFn: async () => {
|
||||
return await getUserInfo();
|
||||
return await getMyInfo();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,29 +1,23 @@
|
||||
import api from '@/lib/api-client';
|
||||
import { ICurrentUser, IUser } from '@/features/user/types/user.types';
|
||||
import api from "@/lib/api-client";
|
||||
import { ICurrentUser, IUser } from "@/features/user/types/user.types";
|
||||
|
||||
export async function getMe(): Promise<IUser> {
|
||||
const req = await api.post<IUser>('/users/me');
|
||||
return req.data as IUser;
|
||||
}
|
||||
|
||||
export async function getUserInfo(): Promise<ICurrentUser> {
|
||||
const req = await api.post<ICurrentUser>('/users/info');
|
||||
export async function getMyInfo(): Promise<ICurrentUser> {
|
||||
const req = await api.post<ICurrentUser>("/users/me");
|
||||
return req.data as ICurrentUser;
|
||||
}
|
||||
|
||||
export async function updateUser(data: Partial<IUser>): Promise<IUser> {
|
||||
const req = await api.post<IUser>('/users/update', data);
|
||||
const req = await api.post<IUser>("/users/update", data);
|
||||
return req.data as IUser;
|
||||
}
|
||||
|
||||
export async function uploadAvatar(file: File) {
|
||||
const formData = new FormData();
|
||||
formData.append('avatar', file);
|
||||
const req = await api.post('/attachments/upload/avatar', formData, {
|
||||
formData.append("avatar", file);
|
||||
const req = await api.post("/attachments/upload/avatar", formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
}
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
});
|
||||
return req.data;
|
||||
}
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { useAtom } from 'jotai';
|
||||
import { currentUserAtom } from '@/features/user/atoms/current-user-atom';
|
||||
import React, { useEffect } from 'react';
|
||||
import useCurrentUser from '@/features/user/hooks/use-current-user';
|
||||
import { useAtom } from "jotai";
|
||||
import { currentUserAtom } from "@/features/user/atoms/current-user-atom";
|
||||
import React, { useEffect } from "react";
|
||||
import useCurrentUser from "@/features/user/hooks/use-current-user";
|
||||
|
||||
export function UserProvider({ children }: React.PropsWithChildren) {
|
||||
const [, setCurrentUser] = useAtom(currentUserAtom);
|
||||
@ -16,6 +16,7 @@ export function UserProvider({ children }: React.PropsWithChildren) {
|
||||
if (isLoading) return <></>;
|
||||
|
||||
if (error) {
|
||||
console.error(error);
|
||||
return <>an error occurred</>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user