Skip to content

Commit

Permalink
Added form handling to new profile form
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei15193 committed Jan 5, 2024
1 parent c3ae1a9 commit 4adf855
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions webApp/app/profile/AddUserProfileDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IUserProfile } from "../../data/userProfiles";
import { type DialogOpenChangeData, type DialogOpenChangeEvent, Button, Dialog, DialogActions, DialogBody, DialogContent, DialogSurface, DialogTitle, DialogTrigger } from "@fluentui/react-components";
import { FormattedMessage } from "react-intl";
import { useCallback, useRef, useState } from "react";
import { type ReactEventHandler, useCallback, useRef, useState } from "react";
import { useViewModel } from "react-model-view-viewmodel";
import { useDependencyResolver } from "../../common/dependencies";
import { FormField, FormInputField } from "../forms";
Expand All @@ -27,8 +27,10 @@ export function AddUserProfileDialog({ onUserProfileAdded }: IAddUserProfileDial
[formRef, setIsDialogOpen]
);

const addUserProfileAsyncCallback = useCallback(
async () => {
const addUserProfileAsyncCallback = useCallback<ReactEventHandler<HTMLElement>>(
async (event) => {
event.preventDefault();

const userProfile = await formRef.current.addAsync();
if (formRef.current.userProfileAdded) {
setIsDialogOpen(false);
Expand All @@ -51,9 +53,11 @@ export function AddUserProfileDialog({ onUserProfileAdded }: IAddUserProfileDial
<FormattedMessage defaultMessage="Add profile" description="Add user profile form caption." />
</DialogTitle>
<DialogContent>
<FormField field={formRef.current.displayName} label="Display name">
<FormInputField />
</FormField>
<form onSubmit={addUserProfileAsyncCallback}>
<FormField field={formRef.current.displayName} label="Display name">
<FormInputField />
</FormField>
</form>
</DialogContent>
<DialogActions>
<DialogTrigger disableButtonEnhancement action="close">
Expand Down

0 comments on commit 4adf855

Please sign in to comment.