-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from ucmo-cs/frontend/customer-menu
feat: final fixes
- Loading branch information
Showing
25 changed files
with
1,608 additions
and
58 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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
134 changes: 134 additions & 0 deletions
134
src/main/frontend/src/components/CreateAccountDialog.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
} from "@/components/ui/dialog.tsx"; | ||
import { | ||
Form, | ||
FormControl, | ||
FormField, | ||
FormItem, | ||
FormLabel, | ||
FormMessage | ||
} from "@/components/ui/form.tsx"; | ||
import {Button} from "@/components/ui/button.tsx"; | ||
import {z} from "zod"; | ||
import {zodResolver} from "@hookform/resolvers/zod"; | ||
import {useForm} from "react-hook-form"; | ||
import {Input} from "@/components/ui/input.tsx"; | ||
|
||
const formSchema = z.object({ | ||
firstName: z.string(), | ||
lastName: z.string(), | ||
email: z.string().email(), | ||
password: z.string(), | ||
}); | ||
|
||
function CreateAccountDialog({toggle}: { toggle?: () => void }) { | ||
|
||
const form = useForm<z.infer<typeof formSchema>>({ | ||
resolver: zodResolver(formSchema), | ||
defaultValues: { | ||
firstName: "", | ||
lastName: "", | ||
email: "", | ||
password: "", | ||
}, | ||
}); | ||
|
||
const onSubmit = (data: z.infer<typeof formSchema>) => { | ||
fetch("/api/account", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
email: data.email, | ||
password: data.password, | ||
username: `${data.firstName} ${data.lastName}`, | ||
}), | ||
}).then((response) => { | ||
if (response.ok) { | ||
form.reset(); | ||
if (toggle) { | ||
toggle(); | ||
} | ||
} else { | ||
console.error(response); | ||
} | ||
}).catch((error) => console.error(error)); | ||
}; | ||
|
||
|
||
return ( | ||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)}> | ||
<DialogHeader className={"mb-5"}> | ||
<DialogTitle>New Account</DialogTitle> | ||
<DialogDescription> | ||
Create a new account by filling out the form below. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<FormField | ||
control={form.control} | ||
name="firstName" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>First Name</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Joe" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="lastName" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Last Name</FormLabel> | ||
<FormControl> | ||
<Input placeholder="Smith" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="email" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Email</FormLabel> | ||
<FormControl> | ||
<Input placeholder="" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<FormField | ||
control={form.control} | ||
name="password" | ||
render={({ field }) => ( | ||
<FormItem> | ||
<FormLabel>Password</FormLabel> | ||
<FormControl> | ||
<Input placeholder="" {...field} /> | ||
</FormControl> | ||
<FormMessage /> | ||
</FormItem> | ||
)} | ||
/> | ||
<DialogFooter className={"mt-2"}> | ||
<Button>Submit</Button> | ||
<Button type={"button"} variant="outline" onClick={toggle}>Cancel</Button> | ||
</DialogFooter> | ||
</form> | ||
</Form> | ||
) | ||
} | ||
|
||
export default CreateAccountDialog; |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React, {cloneElement} from "react"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogTrigger | ||
} from "@/components/ui/dialog.tsx"; | ||
import {Button} from "@/components/ui/button.tsx"; | ||
import {FilePlus2} from "lucide-react"; | ||
|
||
|
||
function DialogSwitcher({ children }: { children: React.ReactNode }) { | ||
const [content, setContent] = React.useState(true); | ||
|
||
const toggleContent = () => { | ||
setContent(prev => !prev); | ||
}; | ||
|
||
const validChildren = React.Children.toArray(children).filter(React.isValidElement); | ||
|
||
return ( | ||
<Dialog> | ||
<DialogTrigger asChild> | ||
<Button variant={"outline"}>Create Loan<FilePlus2/></Button> | ||
</DialogTrigger> | ||
<DialogContent> | ||
{content ? cloneElement(validChildren[0] as React.ReactElement, { toggle: toggleContent }) : cloneElement(validChildren[1] as React.ReactElement, { toggle: toggleContent })} | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
} | ||
|
||
export default DialogSwitcher; |
Oops, something went wrong.