mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on the API route for upload and the ping. adding types for actions.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"use client"
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {useMutation} from "@tanstack/react-query";
|
||||
import {backupButtonAction} from "@/components/wrappers/BackupButton/backup-button.action";
|
||||
|
||||
export type BackupButtonProps = {
|
||||
// databaseId: string;
|
||||
}
|
||||
|
||||
export const BackupButton = () => {
|
||||
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: async (databaseId: string) => {
|
||||
const result = await backupButtonAction(databaseId)
|
||||
console.log(result)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return (
|
||||
<Button
|
||||
onClick={() => {
|
||||
mutation.mutateAsync("cm430tnop0001bcm0vo9b5nfx")
|
||||
}}
|
||||
>Backup
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
"use server"
|
||||
import {userAction} from "@/safe-actions";
|
||||
import {z} from "zod";
|
||||
import {prisma} from "@/prisma";
|
||||
import {ServerActionResult} from "@/types/action-type";
|
||||
import {Backup} from "@prisma/client";
|
||||
|
||||
|
||||
|
||||
export const backupButtonAction = userAction
|
||||
.schema(z.string())
|
||||
.action(async ({ parsedInput, ctx }): Promise<ServerActionResult<Backup>> => {
|
||||
try {
|
||||
const backup = await prisma.backup.create({
|
||||
data: {
|
||||
databaseId: parsedInput,
|
||||
status: "waiting",
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
value: backup,
|
||||
actionSuccess: {
|
||||
message: "Backup has been successfully created.",
|
||||
messageParams: { databaseId: parsedInput },
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error creating backup:", error);
|
||||
|
||||
return {
|
||||
success: false,
|
||||
actionError: {
|
||||
message: "Failed to create backup.",
|
||||
status: 500, // Optional: Use a meaningful status code
|
||||
cause: error instanceof Error ? error.message : "Unknown error",
|
||||
messageParams: { databaseId: parsedInput },
|
||||
},
|
||||
};
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user