Skip to content

Commit a708d56

Browse files
committed
test: update examples to test file uploads
1 parent d5e59cf commit a708d56

File tree

4 files changed

+52
-13
lines changed

4 files changed

+52
-13
lines changed

.hintrc

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
],
55
"hints": {
66
"typescript-config/consistent-casing": "off",
7-
"typescript-config/strict": "off"
7+
"typescript-config/strict": "off",
8+
"axe/forms": [
9+
"default",
10+
{
11+
"label": "off"
12+
}
13+
]
814
}
915
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"use server";
2+
import { action, zodFile } from "@davstack/action";
3+
export const uploadFile = action()
4+
.input({
5+
file: zodFile({ type: "*" }),
6+
})
7+
.mutation(async ({ input, ctx }) => {
8+
console.log("FILE UPLOADING! ", { input, ctx });
9+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use client";
2+
import { objectToFormData } from "@davstack/action";
3+
import { uploadFile } from "./file.action";
4+
export interface FilePageProps {}
5+
6+
export default function FilePage(props: FilePageProps) {
7+
const {} = props;
8+
9+
return (
10+
<>
11+
<form action={uploadFile as any}>
12+
<input type="file" name="file" />
13+
<button type="submit">Upload via form action</button>
14+
</form>
15+
16+
<button
17+
onClick={async () => {
18+
try {
19+
const file = new Blob([], { type: "123" });
20+
await uploadFile(objectToFormData({ file }));
21+
} catch (e) {
22+
console.error(e);
23+
}
24+
}}
25+
>
26+
upload via direct action call
27+
</button>
28+
</>
29+
);
30+
}

examples/t3-with-davstack/src/app/with-server-actions/actions.tsx

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"use server";
22

3-
import { unstable_cache } from 'next/cache';
43
import { authedAction } from "@/lib/action";
5-
import { revalidatePath } from "next/cache";
64
import { z } from "zod";
75

86
export const getTodos = authedAction.query(async ({ ctx }) => {
@@ -16,16 +14,12 @@ export const getTodos = authedAction.query(async ({ ctx }) => {
1614
export const createTodo = authedAction
1715
.input({ name: z.string().min(1) })
1816
.mutation(async ({ ctx, input }) => {
19-
return ctx.db.todo
20-
.create({
21-
data: {
22-
name: input.name,
23-
createdBy: { connect: { id: ctx.user.id } },
24-
},
25-
})
26-
.then(() => {
27-
// revalidatePath("/with-server-actions");
28-
});
17+
return ctx.db.todo.create({
18+
data: {
19+
name: input.name,
20+
createdBy: { connect: { id: ctx.user.id } },
21+
},
22+
});
2923
});
3024

3125
export const updateTodo = authedAction

0 commit comments

Comments
 (0)