File tree 4 files changed +52
-13
lines changed
examples/t3-with-davstack/src/app
4 files changed +52
-13
lines changed Original file line number Diff line number Diff line change 4
4
],
5
5
"hints": {
6
6
"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
+ ]
8
14
}
9
15
}
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
"use server" ;
2
2
3
- import { unstable_cache } from 'next/cache' ;
4
3
import { authedAction } from "@/lib/action" ;
5
- import { revalidatePath } from "next/cache" ;
6
4
import { z } from "zod" ;
7
5
8
6
export const getTodos = authedAction . query ( async ( { ctx } ) => {
@@ -16,16 +14,12 @@ export const getTodos = authedAction.query(async ({ ctx }) => {
16
14
export const createTodo = authedAction
17
15
. input ( { name : z . string ( ) . min ( 1 ) } )
18
16
. 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
+ } ) ;
29
23
} ) ;
30
24
31
25
export const updateTodo = authedAction
You can’t perform that action at this time.
0 commit comments