fix(web): token not being saved
This commit is contained in:
		
							parent
							
								
									850d8473ad
								
							
						
					
					
						commit
						ecf0c277f6
					
				@ -14,6 +14,7 @@ import {
 | 
				
			|||||||
  DialogTrigger,
 | 
					  DialogTrigger,
 | 
				
			||||||
} from "@/components/ui/dialog";
 | 
					} from "@/components/ui/dialog";
 | 
				
			||||||
import * as React from "react";
 | 
					import * as React from "react";
 | 
				
			||||||
 | 
					import { useState } from "react";
 | 
				
			||||||
import type { UnknownKeysParam, ZodObject, ZodRawShape, z } from "zod";
 | 
					import type { UnknownKeysParam, ZodObject, ZodRawShape, z } from "zod";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function InsertModal<
 | 
					export function InsertModal<
 | 
				
			||||||
@ -83,8 +84,13 @@ export function UpdateModal<
 | 
				
			|||||||
  fieldConfig?: FieldConfig<z.infer<Z>>;
 | 
					  fieldConfig?: FieldConfig<z.infer<Z>>;
 | 
				
			||||||
}) {
 | 
					}) {
 | 
				
			||||||
  // const [open, setOpen] = React.useState(false);
 | 
					  // const [open, setOpen] = React.useState(false);
 | 
				
			||||||
 | 
					  const [values, setValues] = useState<Partial<z.infer<Z>>>({});
 | 
				
			||||||
  const [isLoading, setIsLoading] = React.useState(false);
 | 
					  const [isLoading, setIsLoading] = React.useState(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  React.useEffect(() => {
 | 
				
			||||||
 | 
					    setValues(props.data);
 | 
				
			||||||
 | 
					  }, [props.data]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <Dialog open={props.open} onOpenChange={props.setOpen}>
 | 
					    <Dialog open={props.open} onOpenChange={props.setOpen}>
 | 
				
			||||||
      {/* <DialogTrigger asChild>
 | 
					      {/* <DialogTrigger asChild>
 | 
				
			||||||
@ -96,6 +102,8 @@ export function UpdateModal<
 | 
				
			|||||||
          <DialogDescription>{props.description}</DialogDescription>
 | 
					          <DialogDescription>{props.description}</DialogDescription>
 | 
				
			||||||
        </DialogHeader>
 | 
					        </DialogHeader>
 | 
				
			||||||
        <AutoForm
 | 
					        <AutoForm
 | 
				
			||||||
 | 
					          values={values}
 | 
				
			||||||
 | 
					          onValuesChange={setValues}
 | 
				
			||||||
          fieldConfig={props.fieldConfig}
 | 
					          fieldConfig={props.fieldConfig}
 | 
				
			||||||
          formSchema={props.formSchema}
 | 
					          formSchema={props.formSchema}
 | 
				
			||||||
          onSubmit={async (data) => {
 | 
					          onSubmit={async (data) => {
 | 
				
			||||||
 | 
				
			|||||||
@ -187,20 +187,6 @@ export const columns: ColumnDef<Machine>[] = [
 | 
				
			|||||||
            </DropdownMenuItem>
 | 
					            </DropdownMenuItem>
 | 
				
			||||||
          </DropdownMenuContent>
 | 
					          </DropdownMenuContent>
 | 
				
			||||||
          <UpdateModal
 | 
					          <UpdateModal
 | 
				
			||||||
            fieldConfig={{
 | 
					 | 
				
			||||||
              name: {
 | 
					 | 
				
			||||||
                inputProps: { defaultValue: machine.name },
 | 
					 | 
				
			||||||
              },
 | 
					 | 
				
			||||||
              endpoint: {
 | 
					 | 
				
			||||||
                inputProps: { defaultValue: machine.endpoint },
 | 
					 | 
				
			||||||
              },
 | 
					 | 
				
			||||||
              type: {
 | 
					 | 
				
			||||||
                inputProps: { defaultValue: machine.type },
 | 
					 | 
				
			||||||
              },
 | 
					 | 
				
			||||||
              auth_token: {
 | 
					 | 
				
			||||||
                inputProps: { defaultValue: machine.auth_token ?? "" },
 | 
					 | 
				
			||||||
              },
 | 
					 | 
				
			||||||
            }}
 | 
					 | 
				
			||||||
            data={machine}
 | 
					            data={machine}
 | 
				
			||||||
            open={open}
 | 
					            open={open}
 | 
				
			||||||
            setOpen={setOpen}
 | 
					            setOpen={setOpen}
 | 
				
			||||||
 | 
				
			|||||||
@ -68,6 +68,11 @@ export const createRun = withServerPromise(
 | 
				
			|||||||
          },
 | 
					          },
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        console.log(data);
 | 
					        console.log(data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!machine.auth_token) {
 | 
				
			||||||
 | 
					          throw new Error("Machine auth token not found");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const __result = await fetch(`${machine.endpoint}/run`, {
 | 
					        const __result = await fetch(`${machine.endpoint}/run`, {
 | 
				
			||||||
          method: "POST",
 | 
					          method: "POST",
 | 
				
			||||||
          headers: {
 | 
					          headers: {
 | 
				
			||||||
 | 
				
			|||||||
@ -23,15 +23,13 @@ export async function getMachines() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const addMachine = withServerPromise(
 | 
					export const addMachine = withServerPromise(
 | 
				
			||||||
  async ({ name, endpoint, type }: z.infer<typeof addMachineSchema>) => {
 | 
					  async (data: z.infer<typeof addMachineSchema>) => {
 | 
				
			||||||
    const { userId } = auth();
 | 
					    const { userId } = auth();
 | 
				
			||||||
    if (!userId) return { error: "No user id" };
 | 
					    if (!userId) return { error: "No user id" };
 | 
				
			||||||
    console.log(name, endpoint);
 | 
					    // console.log(name, endpoint);
 | 
				
			||||||
    await db.insert(machinesTable).values({
 | 
					    await db.insert(machinesTable).values({
 | 
				
			||||||
 | 
					      ...data,
 | 
				
			||||||
      user_id: userId,
 | 
					      user_id: userId,
 | 
				
			||||||
      name,
 | 
					 | 
				
			||||||
      endpoint,
 | 
					 | 
				
			||||||
      type,
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    revalidatePath("/machines");
 | 
					    revalidatePath("/machines");
 | 
				
			||||||
    return { message: "Machine Added" };
 | 
					    return { message: "Machine Added" };
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user