-
Notifications
You must be signed in to change notification settings - Fork 10
Improve Submissions integration UI #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3d7244e
Remove generic assertion error; use localhost in dev seed data
3mcd 3426257
Use localhost for evaluations integration in dev
3mcd ceb2bef
Add several shadcn components; improve submission integration config UI
3mcd 26ddcf5
Style submissions integration forms; add new components to ui; add re…
3mcd 78031ad
Add min length to title; remove esbuild plugin
3mcd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,12 @@ | ||
| import { client } from "~/lib/pubpub"; | ||
| import { Submit } from "./submit"; | ||
|
|
||
| type Props = { | ||
| searchParams: { | ||
| instanceId: string; | ||
| token: string; | ||
| }; | ||
| }; | ||
|
|
||
| export default async function Page(props: Props) { | ||
| const { instanceId, token } = props.searchParams; | ||
| const user = await client.auth(instanceId, token); | ||
|
|
||
| return ( | ||
| <main> | ||
| <p>Hello {user.name}</p> | ||
| <img src={`${process.env.PUBPUB_URL}/${user.avatar}`} /> | ||
| <Submit instanceId={instanceId} /> | ||
| </main> | ||
| ); | ||
| const { instanceId } = props.searchParams; | ||
| return <Submit instanceId={instanceId} />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,112 @@ | ||
| "use client"; | ||
|
|
||
| import { useState, useTransition } from "react"; | ||
| import { zodResolver } from "@hookform/resolvers/zod"; | ||
| import { useForm } from "react-hook-form"; | ||
| import { | ||
| Button, | ||
| Form, | ||
| FormControl, | ||
| FormDescription, | ||
| FormField, | ||
| FormItem, | ||
| FormLabel, | ||
| FormMessage, | ||
| Icon, | ||
| Input, | ||
| useToast, | ||
| Card, | ||
| CardHeader, | ||
| CardFooter, | ||
| CardContent, | ||
| CardTitle, | ||
| CardDescription, | ||
| } from "ui"; | ||
| import { cn } from "utils"; | ||
| import * as z from "zod"; | ||
| import { submit } from "./actions"; | ||
|
|
||
| type Props = { | ||
| instanceId: string; | ||
| }; | ||
|
|
||
| const schema = z.object({ | ||
| Title: z.string().min(1), | ||
| instanceId: z.string(), | ||
| }); | ||
|
|
||
| export function Submit(props: Props) { | ||
| const [message, setMessage] = useState<string>(""); | ||
| const [isPending, startTransition] = useTransition(); | ||
| const { toast } = useToast(); | ||
| const form = useForm<z.infer<typeof schema>>({ | ||
| resolver: zodResolver(schema), | ||
| defaultValues: { | ||
| Title: "", | ||
| instanceId: props.instanceId, | ||
| }, | ||
| }); | ||
|
|
||
| async function onSubmit(form: FormData) { | ||
| const response = await submit(form); | ||
| setMessage("error" in response ? response.error : "Pub submitted!"); | ||
| async function onSubmit(values: z.infer<typeof schema>) { | ||
| const { instanceId, ...pub } = values; | ||
| const result = await submit(instanceId, pub); | ||
| if ("error" in result) { | ||
| toast({ | ||
| title: "Error", | ||
| description: result.error, | ||
| variant: "destructive", | ||
| }); | ||
| } else { | ||
| toast({ | ||
| title: "Success", | ||
| description: "The pub was created successfully.", | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <form action={(form) => startTransition(() => onSubmit(form))}> | ||
| <label> | ||
| <span>Title</span> | ||
| <input type="text" name="Title" /> | ||
| </label> | ||
| <input type="hidden" name="instance-id" value={props.instanceId} /> | ||
| <button type="submit">Submit</button> | ||
| <p>{isPending ? "Submitting Pub..." : message}</p> | ||
| </form> | ||
| <Form {...form}> | ||
| <form onSubmit={form.handleSubmit(onSubmit)}> | ||
| <Card> | ||
| <CardHeader> | ||
| <CardTitle>Submit Pub</CardTitle> | ||
| <CardDescription> | ||
| This form will create a pub from the fields below. | ||
| </CardDescription> | ||
| </CardHeader> | ||
| <CardContent> | ||
| <Input type="hidden" name="instanceId" value={props.instanceId} /> | ||
| <FormField | ||
| control={form.control} | ||
| name="Title" | ||
| render={({ field }) => ( | ||
| <FormItem> | ||
| <FormLabel>Title</FormLabel> | ||
| <FormControl> | ||
| <Input {...field} /> | ||
| </FormControl> | ||
| <FormDescription>The title of the pub.</FormDescription> | ||
| <FormMessage /> | ||
| </FormItem> | ||
| )} | ||
| /> | ||
| </CardContent> | ||
| <CardFooter className={cn("flex justify-between")}> | ||
| <Button | ||
| variant="outline" | ||
| onClick={(e) => { | ||
| e.preventDefault(); | ||
| window.history.back(); | ||
| }} | ||
| > | ||
| Go Back | ||
| </Button> | ||
| <Button type="submit" disabled={!form.formState.isValid}> | ||
| Submit Pub | ||
| {form.formState.isSubmitting && ( | ||
| <Icon.Spinner className="h-4 w-4 ml-4 animate-spin" /> | ||
| )} | ||
| </Button> | ||
| </CardFooter> | ||
| </Card> | ||
| </form> | ||
| </Form> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed some typical
keywarnings.