user in header
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { getToken } from "@/config/func";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import * as api from "../service/BusinessService";
|
||||
|
||||
@@ -16,3 +17,11 @@ export const useGetBusinessBySlug = (slug: string) => {
|
||||
enabled: !!slug,
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetBusiness = () => {
|
||||
return useQuery({
|
||||
queryKey: ["mybusiness"],
|
||||
queryFn: api.getBusiness,
|
||||
enabled: !!getToken(),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import axios from "@/config/axios";
|
||||
import type { CatalogResponseType } from "@/pages/catalogue/types/Types";
|
||||
import type { BusinessResponseType } from "../types/Types";
|
||||
|
||||
export const getBusinessCatalog = async (slug: string) => {
|
||||
const { data } = await axios.get<CatalogResponseType>(
|
||||
@@ -12,3 +13,8 @@ export const getBusinessBySlug = async (slug: string) => {
|
||||
const { data } = await axios.get(`/public/business/${slug}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getBusiness = async () => {
|
||||
const { data } = await axios.get<BusinessResponseType>(`/admin/business/me`);
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import type { BaseResponse } from "@/shared/types/SharedTypes";
|
||||
|
||||
export type AdminType = {
|
||||
business: string;
|
||||
createdAt: string;
|
||||
deletedAt: string | null;
|
||||
firstName: string;
|
||||
id: string;
|
||||
lastName: string;
|
||||
phone: string;
|
||||
};
|
||||
|
||||
export type BusinessType = {
|
||||
id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
logoUrl: string | null;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
deletedAt: string | null;
|
||||
admin: AdminType;
|
||||
};
|
||||
|
||||
export type BusinessResponseType = BaseResponse<BusinessType>;
|
||||
|
||||
export const getAdminFullName = (admin?: AdminType | null): string =>
|
||||
[admin?.firstName, admin?.lastName].filter(Boolean).join(" ");
|
||||
Reference in New Issue
Block a user