feat: add hosts management

This commit is contained in:
2024-11-09 10:33:07 +00:00
parent 31c43836f4
commit d931235fb3
27 changed files with 742 additions and 94 deletions
+3
View File
@@ -1,3 +1,4 @@
import { QueryClient } from "@tanstack/react-query";
import { ofetch } from "ofetch";
export const BASE_API_URL = process.env.EXPO_PUBLIC_API_URL || ""; //"http://10.0.0.100:3000";
@@ -7,4 +8,6 @@ const api = ofetch.create({
baseURL: BASE_API_URL,
});
export const queryClient = new QueryClient();
export default api;
+38
View File
@@ -0,0 +1,38 @@
import { z } from "zod";
import { createStore, useStore } from "zustand";
export const createDisclosure = <T>(data?: T | null) => {
const store = createStore(() => ({
open: false,
data: data,
}));
const onOpen = (data?: T | null) => {
store.setState({ open: true, data });
};
const onClose = () => {
store.setState({ open: false });
};
const onOpenChange = (open: boolean) => {
store.setState({ open });
};
const use = () => {
const state = useStore(store);
return { ...state, onOpen, onClose, onOpenChange };
};
return { store, use, onOpen, onClose, onOpenChange };
};
const hostnameRegex =
/^(?:(?:[a-zA-Z0-9-]{1,63}\.?)+[a-zA-Z]{0,63}|(?:\d{1,3}\.){3}\d{1,3}|(?:[a-fA-F0-9:]+:+)+[a-fA-F0-9]+)$/;
export const isHostnameOrIP = (value?: string | null) => {
return hostnameRegex.test(value || "");
};
export const hostnameShape = (message: string = "Invalid hostname") =>
z.string().refine(isHostnameOrIP, { message });