namespace logic
This commit is contained in:
parent
60ba131b81
commit
be1be20864
|
|
@ -2,11 +2,13 @@ import { z } from "zod";
|
|||
import { chainSchema } from "../schema";
|
||||
import { getAxios } from "@/shared/lib/getAxios";
|
||||
|
||||
export async function getChainList() {
|
||||
export async function getChainList(namespaceId: string) {
|
||||
const axios = getAxios();
|
||||
|
||||
try {
|
||||
const response = await axios.get("/chain/list/");
|
||||
const response = await axios.get("/chain/list/", {
|
||||
params: { namespace_id: namespaceId },
|
||||
});
|
||||
return z.array(chainSchema).parse(response.data);
|
||||
} catch {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { actionSchema } from "../action/schema";
|
|||
|
||||
export const chainSchema = z.object({
|
||||
_id: z.string().uuid().optional(),
|
||||
namespaceId: z.string().uuid(),
|
||||
name: z.string().nullable(),
|
||||
actions: z.array(actionSchema).optional(),
|
||||
lastModified: z.string().optional(),
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { useNavigate } from "@tanstack/react-router";
|
|||
import { chainSchema } from "@/entities/chain/schema";
|
||||
import { upsertChain } from "@/entities/chain/api/upsert";
|
||||
import { useChainState } from "@/entities/chain/model";
|
||||
import { useParams } from "@tanstack/react-router";
|
||||
|
||||
import Dialog from "@mui/material/Dialog";
|
||||
import DialogActions from "@mui/material/DialogActions";
|
||||
|
|
@ -19,6 +20,7 @@ export default function AddChainButton({ children }: AddChainButtonProps) {
|
|||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [isError, setIsError] = useState(false);
|
||||
const { namespace } = useParams({ from: "/$namespace/$chainId" });
|
||||
|
||||
const navigate = useNavigate({ from: "/$namespace/$chainId" });
|
||||
const addChain = useChainState((state) => state.addChain);
|
||||
|
|
@ -28,7 +30,10 @@ export default function AddChainButton({ children }: AddChainButtonProps) {
|
|||
setLoading(true);
|
||||
|
||||
const formData = new FormData(event.currentTarget);
|
||||
const validatedData = chainSchema.parse(Object.fromEntries(formData));
|
||||
const validatedData = chainSchema.parse({
|
||||
...Object.fromEntries(formData),
|
||||
namespaceId: namespace,
|
||||
});
|
||||
|
||||
const createdChain = await upsertChain(validatedData);
|
||||
setLoading(false);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ function ChainPage() {
|
|||
export const Route = createFileRoute("/$namespace/$chainId")({
|
||||
component: ChainPage,
|
||||
loader: async ({ params }) => {
|
||||
await requireChains();
|
||||
await requireChains(params.namespace);
|
||||
const chainState = useChainState.getState();
|
||||
const chains = chainState.chains;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ function IndexPage() {
|
|||
export const Route = createFileRoute("/$namespace/")({
|
||||
component: IndexPage,
|
||||
loader: async ({ params }) => {
|
||||
await requireChains();
|
||||
await requireChains(params.namespace);
|
||||
const chains = useChainState.getState().chains;
|
||||
|
||||
if (typeof chains === "undefined") throw redirect({ to: "/" });
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user