fix: rename useAdmin
to useApiServices
This commit is contained in:
@ -2,7 +2,7 @@ import { createPortal } from "react-dom";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { X } from "lucide-react";
|
import { X } from "lucide-react";
|
||||||
import { useAdmin } from "@/store/admin";
|
import { useApiServices } from "@/store/admin";
|
||||||
import type { ApiServiceCredentials } from "@/types";
|
import type { ApiServiceCredentials } from "@/types";
|
||||||
|
|
||||||
const download = (credentials: ApiServiceCredentials) => {
|
const download = (credentials: ApiServiceCredentials) => {
|
||||||
@ -19,8 +19,8 @@ const download = (credentials: ApiServiceCredentials) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const ApiServiceCredentialsModal = () => {
|
const ApiServiceCredentialsModal = () => {
|
||||||
const credentials = useAdmin((state) => state.createdCredentials);
|
const credentials = useApiServices((state) => state.createdCredentials);
|
||||||
const resetCredentials = useAdmin((state) => state.resetCredentials);
|
const resetCredentials = useApiServices((state) => state.resetCredentials);
|
||||||
|
|
||||||
const portalRoot = document.getElementById("portal-root");
|
const portalRoot = document.getElementById("portal-root");
|
||||||
if (!portalRoot || !credentials) return null;
|
if (!portalRoot || !credentials) return null;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { createPortal } from "react-dom";
|
import { createPortal } from "react-dom";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { CircleCheckBig, X } from "lucide-react";
|
import { CircleCheckBig, X } from "lucide-react";
|
||||||
import { useAdmin } from "@/store/admin";
|
import { useApiServices } from "@/store/admin";
|
||||||
|
|
||||||
const ApiServiceUpdatedModal = () => {
|
const ApiServiceUpdatedModal = () => {
|
||||||
const resetUpdated = useAdmin((state) => state.resetUpdatedApiService);
|
const resetUpdated = useApiServices((state) => state.resetUpdated);
|
||||||
|
|
||||||
const portalRoot = document.getElementById("portal-root");
|
const portalRoot = document.getElementById("portal-root");
|
||||||
if (!portalRoot) return null;
|
if (!portalRoot) return null;
|
||||||
|
@ -2,7 +2,7 @@ import Breadcrumbs from "@/components/ui/breadcrumbs";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import ApiServiceCredentialsModal from "@/feature/ApiServiceCredentialsModal";
|
import ApiServiceCredentialsModal from "@/feature/ApiServiceCredentialsModal";
|
||||||
import { useAdmin } from "@/store/admin";
|
import { useApiServices } from "@/store/admin";
|
||||||
import { useCallback, type FC } from "react";
|
import { useCallback, type FC } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { Link } from "react-router";
|
import { Link } from "react-router";
|
||||||
@ -28,9 +28,9 @@ const ApiServiceCreatePage: FC = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const createApiService = useAdmin((state) => state.createApiService);
|
const createApiService = useApiServices((state) => state.create);
|
||||||
|
|
||||||
const credentials = useAdmin((state) => state.createdCredentials);
|
const credentials = useApiServices((state) => state.createdCredentials);
|
||||||
|
|
||||||
const onSubmit = useCallback(
|
const onSubmit = useCallback(
|
||||||
(data: FormData) => {
|
(data: FormData) => {
|
||||||
|
@ -2,7 +2,7 @@ import Breadcrumbs from "@/components/ui/breadcrumbs";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import ApiServiceUpdatedModal from "@/feature/ApiServiceUpdatedModal";
|
import ApiServiceUpdatedModal from "@/feature/ApiServiceUpdatedModal";
|
||||||
import { useAdmin } from "@/store/admin";
|
import { useApiServices } from "@/store/admin";
|
||||||
import { useCallback, useEffect, type FC } from "react";
|
import { useCallback, useEffect, type FC } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { Link, useParams } from "react-router";
|
import { Link, useParams } from "react-router";
|
||||||
@ -28,13 +28,13 @@ const ApiServiceEditPage: FC = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const { serviceId } = useParams();
|
const { serviceId } = useParams();
|
||||||
const apiService = useAdmin((state) => state.viewApiService);
|
const apiService = useApiServices((state) => state.view);
|
||||||
|
|
||||||
const loadService = useAdmin((state) => state.fetchApiService);
|
const loadService = useApiServices((state) => state.fetch);
|
||||||
|
|
||||||
const updateApiService = useAdmin((state) => state.updateApiService);
|
const updateApiService = useApiServices((state) => state.update);
|
||||||
const updating = useAdmin((state) => state.updatingApiService);
|
const updating = useApiServices((state) => state.updating);
|
||||||
const updated = useAdmin((state) => state.updatedApiService);
|
const updated = useApiServices((state) => state.updated);
|
||||||
|
|
||||||
const onSubmit = useCallback(
|
const onSubmit = useCallback(
|
||||||
(data: FormData) => {
|
(data: FormData) => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Breadcrumbs from "@/components/ui/breadcrumbs";
|
import Breadcrumbs from "@/components/ui/breadcrumbs";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { useAdmin } from "@/store/admin";
|
import { useApiServices } from "@/store/admin";
|
||||||
import { useEffect, type FC } from "react";
|
import { useEffect, type FC } from "react";
|
||||||
import { Link, useParams } from "react-router";
|
import { Link, useParams } from "react-router";
|
||||||
|
|
||||||
@ -24,13 +24,13 @@ const InfoCard = ({
|
|||||||
|
|
||||||
const ViewApiServicePage: FC = () => {
|
const ViewApiServicePage: FC = () => {
|
||||||
const { serviceId } = useParams();
|
const { serviceId } = useParams();
|
||||||
const apiService = useAdmin((state) => state.viewApiService);
|
const apiService = useApiServices((state) => state.view);
|
||||||
// const loading = useAdmin((state) => state.fetchingApiService);
|
// const loading = useApiServices((state) => state.fetchingApiService);
|
||||||
|
|
||||||
const loadService = useAdmin((state) => state.fetchApiService);
|
const loadService = useApiServices((state) => state.fetchSingle);
|
||||||
|
|
||||||
const toggling = useAdmin((state) => state.togglingApiService);
|
const toggling = useApiServices((state) => state.toggling);
|
||||||
const toggle = useAdmin((state) => state.toggleApiService);
|
const toggle = useApiServices((state) => state.toggle);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (typeof serviceId === "string") loadService(serviceId);
|
if (typeof serviceId === "string") loadService(serviceId);
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
import Breadcrumbs from "@/components/ui/breadcrumbs";
|
import Breadcrumbs from "@/components/ui/breadcrumbs";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useAdmin } from "@/store/admin";
|
import { useApiServices } from "@/store/admin";
|
||||||
import { Plus } from "lucide-react";
|
import { Plus } from "lucide-react";
|
||||||
import { useEffect, type FC } from "react";
|
import { useEffect, type FC } from "react";
|
||||||
import { Link } from "react-router";
|
import { Link } from "react-router";
|
||||||
|
|
||||||
const ApiServicesPage: FC = () => {
|
const ApiServicesPage: FC = () => {
|
||||||
const apiServices = useAdmin((state) => state.apiServices);
|
const apiServices = useApiServices((state) => state.apiServices);
|
||||||
const loading = useAdmin((state) => state.loadingApiServices);
|
const loading = useApiServices((state) => state.loading);
|
||||||
const fetchApiServices = useAdmin((state) => state.fetchApiServices);
|
const fetchApiServices = useApiServices((state) => state.fetch);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchApiServices();
|
fetchApiServices();
|
||||||
|
@ -10,51 +10,51 @@ import {
|
|||||||
import type { ApiService, ApiServiceCredentials } from "@/types";
|
import type { ApiService, ApiServiceCredentials } from "@/types";
|
||||||
import { create } from "zustand";
|
import { create } from "zustand";
|
||||||
|
|
||||||
interface IAdminState {
|
interface IApiServicesState {
|
||||||
apiServices: ApiService[];
|
apiServices: ApiService[];
|
||||||
loadingApiServices: boolean;
|
loading: boolean;
|
||||||
|
|
||||||
createdCredentials: ApiServiceCredentials | null;
|
createdCredentials: ApiServiceCredentials | null;
|
||||||
creatingApiService: boolean;
|
creating: boolean;
|
||||||
|
|
||||||
viewApiService: ApiService | null;
|
view: ApiService | null;
|
||||||
fetchingApiService: boolean;
|
fetching: boolean;
|
||||||
|
|
||||||
fetchApiServices: () => Promise<void>;
|
fetch: () => Promise<void>;
|
||||||
fetchApiService: (id: string) => Promise<void>;
|
fetchSingle: (id: string) => Promise<void>;
|
||||||
createApiService: (req: CreateApiServiceRequest) => Promise<void>;
|
create: (req: CreateApiServiceRequest) => Promise<void>;
|
||||||
resetCredentials: () => void;
|
resetCredentials: () => void;
|
||||||
|
|
||||||
togglingApiService: boolean;
|
toggling: boolean;
|
||||||
toggleApiService: () => Promise<void>;
|
toggle: () => Promise<void>;
|
||||||
|
|
||||||
updateApiService: (req: UpdateApiServiceRequest) => Promise<void>;
|
update: (req: UpdateApiServiceRequest) => Promise<void>;
|
||||||
updatingApiService: boolean;
|
updating: boolean;
|
||||||
updatedApiService: boolean;
|
updated: boolean;
|
||||||
|
|
||||||
resetUpdatedApiService: () => void;
|
resetUpdated: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useAdmin = create<IAdminState>((set, get) => ({
|
export const useApiServices = create<IApiServicesState>((set, get) => ({
|
||||||
apiServices: [],
|
apiServices: [],
|
||||||
loadingApiServices: false,
|
loading: false,
|
||||||
|
|
||||||
createdCredentials: null,
|
createdCredentials: null,
|
||||||
creatingApiService: false,
|
creating: false,
|
||||||
|
|
||||||
viewApiService: null,
|
view: null,
|
||||||
fetchingApiService: false,
|
fetching: false,
|
||||||
|
|
||||||
togglingApiService: false,
|
toggling: false,
|
||||||
|
|
||||||
updatingApiService: false,
|
updating: false,
|
||||||
updatedApiService: false,
|
updated: false,
|
||||||
resetUpdatedApiService: () => set({ updatedApiService: false }),
|
resetUpdated: () => set({ updated: false }),
|
||||||
|
|
||||||
resetCredentials: () => set({ createdCredentials: null }),
|
resetCredentials: () => set({ createdCredentials: null }),
|
||||||
|
|
||||||
fetchApiServices: async () => {
|
fetch: async () => {
|
||||||
set({ loadingApiServices: true });
|
set({ loading: true });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await getApiServices();
|
const response = await getApiServices();
|
||||||
@ -62,58 +62,58 @@ export const useAdmin = create<IAdminState>((set, get) => ({
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("ERR: Failed to fetch services:", err);
|
console.log("ERR: Failed to fetch services:", err);
|
||||||
} finally {
|
} finally {
|
||||||
set({ loadingApiServices: false });
|
set({ loading: false });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchApiService: async (id: string) => {
|
fetchSingle: async (id: string) => {
|
||||||
set({ fetchingApiService: true });
|
set({ fetching: true });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await getApiService(id);
|
const response = await getApiService(id);
|
||||||
set({ viewApiService: response });
|
set({ view: response });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("ERR: Failed to fetch services:", err);
|
console.log("ERR: Failed to fetch services:", err);
|
||||||
} finally {
|
} finally {
|
||||||
set({ fetchingApiService: false });
|
set({ fetching: false });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updateApiService: async (req: UpdateApiServiceRequest) => {
|
update: async (req: UpdateApiServiceRequest) => {
|
||||||
const viewService = get().viewApiService;
|
const viewService = get().view;
|
||||||
if (!viewService) return;
|
if (!viewService) return;
|
||||||
|
|
||||||
set({ updatingApiService: true });
|
set({ updating: true });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await putApiService(viewService.id, req);
|
await putApiService(viewService.id, req);
|
||||||
get().fetchApiService(viewService.id);
|
get().fetchSingle(viewService.id);
|
||||||
set({ updatedApiService: true });
|
set({ updated: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("ERR: Failed to toggle service:", err);
|
console.log("ERR: Failed to toggle service:", err);
|
||||||
} finally {
|
} finally {
|
||||||
set({ updatingApiService: false });
|
set({ updating: false });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleApiService: async () => {
|
toggle: async () => {
|
||||||
const viewService = get().viewApiService;
|
const viewService = get().view;
|
||||||
if (!viewService) return;
|
if (!viewService) return;
|
||||||
|
|
||||||
set({ togglingApiService: true });
|
set({ toggling: true });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await patchToggleApiService(viewService.id);
|
await patchToggleApiService(viewService.id);
|
||||||
get().fetchApiService(viewService.id);
|
get().fetchSingle(viewService.id);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("ERR: Failed to toggle service:", err);
|
console.log("ERR: Failed to toggle service:", err);
|
||||||
} finally {
|
} finally {
|
||||||
set({ togglingApiService: false });
|
set({ toggling: false });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
createApiService: async (req: CreateApiServiceRequest) => {
|
create: async (req: CreateApiServiceRequest) => {
|
||||||
set({ creatingApiService: true });
|
set({ creating: true });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await postApiService(req);
|
const response = await postApiService(req);
|
||||||
@ -121,7 +121,7 @@ export const useAdmin = create<IAdminState>((set, get) => ({
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("ERR: Failed to fetch services:", err);
|
console.log("ERR: Failed to fetch services:", err);
|
||||||
} finally {
|
} finally {
|
||||||
set({ creatingApiService: false });
|
set({ creating: false });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
@ -3,7 +3,7 @@ export interface UserProfile {
|
|||||||
full_name: string;
|
full_name: string;
|
||||||
email: string;
|
email: string;
|
||||||
phone_number: string;
|
phone_number: string;
|
||||||
isAdmin: boolean;
|
is_admin: boolean;
|
||||||
last_login: string;
|
last_login: string;
|
||||||
profile_picture: string | null;
|
profile_picture: string | null;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
|
Reference in New Issue
Block a user