mirror of
https://github.com/khairul169/vaulterm.git
synced 2026-09-15 17:03:30 +07:00
feat: add hosts management
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 });
|
||||
Reference in New Issue
Block a user