-
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.
- Loading branch information
1 parent
67095c0
commit 8b7ae04
Showing
10 changed files
with
183 additions
and
11 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
.root { | ||
cursor: pointer; | ||
cursor: pointer !important; | ||
} |
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,6 @@ | ||
.input { | ||
/* Fix radix's input issue */ | ||
input[type="date"] { | ||
display: block; | ||
} | ||
} |
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,47 @@ | ||
import * as Label from "@radix-ui/react-label"; | ||
import { Flex, Text, TextArea } from "@radix-ui/themes"; | ||
import { ComponentPropsWithoutRef, forwardRef } from "react"; | ||
import styles from "./InputArea.module.css"; | ||
|
||
interface Props extends ComponentPropsWithoutRef<"textarea"> { | ||
label?: string; | ||
error?: string; | ||
"data-testid"?: string; | ||
} | ||
|
||
export const InputArea = forwardRef<HTMLTextAreaElement, Props>( | ||
function InputArea(props, ref) { | ||
const { onChange, error, id, name, placeholder, label, required } = props; | ||
return ( | ||
<Flex direction="column" gap="1"> | ||
{label && ( | ||
<Label.Root htmlFor={name}> | ||
<Text weight="bold" size="2"> | ||
{label} | ||
</Text> | ||
{required && ( | ||
<Text color="red" weight="bold" size="2"> | ||
* | ||
</Text> | ||
)} | ||
</Label.Root> | ||
)} | ||
<TextArea | ||
id={id} | ||
ref={ref} | ||
name={name} | ||
required={required} | ||
onChange={onChange} | ||
className={styles.input} | ||
placeholder={placeholder} | ||
data-testid={props["data-testid"]} | ||
/> | ||
{error && ( | ||
<Text size="2" color="red"> | ||
{error} | ||
</Text> | ||
)} | ||
</Flex> | ||
); | ||
} | ||
); |
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
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
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,95 @@ | ||
import { Alert } from "@@/common/components/Alert/Alert"; | ||
import { Button } from "@@/common/components/Button/Button"; | ||
import { Input } from "@@/common/components/Input/Input"; | ||
import { InputArea } from "@@/common/components/InputArea/InputArea"; | ||
import { PageMeta } from "@@/common/components/PageMeta/PageMeta"; | ||
import { PageTitle } from "@@/common/components/PageTitle/PageTitle"; | ||
import { apiClients, getApiError } from "@@/common/libs/backendapi/browser"; | ||
import { usePaths } from "@@/paths"; | ||
import { Flex, Grid } from "@radix-ui/themes"; | ||
import { useFormik } from "formik"; | ||
import { useState } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import * as yup from "yup"; | ||
|
||
export function CreateEventTypePage() { | ||
const paths = usePaths(); | ||
const navigate = useNavigate(); | ||
const [error, setError] = useState(""); | ||
|
||
const f = useFormik({ | ||
initialValues, | ||
validateOnChange: false, | ||
validationSchema, | ||
onSubmit: async (values) => { | ||
console.log(values); | ||
try { | ||
await apiClients().EventTypes.createEventType(values); | ||
navigate(paths.urls.eventTypes); | ||
} catch (error) { | ||
setError(getApiError(error)); | ||
} | ||
}, | ||
}); | ||
|
||
return ( | ||
<form onSubmitCapture={f.handleSubmit}> | ||
<PageMeta title="Create event type" /> | ||
|
||
<Flex justify="between" mb="4"> | ||
<PageTitle title="Create event type" /> | ||
</Flex> | ||
|
||
<Flex direction="column" gap="2" mb="4"> | ||
<Input | ||
required | ||
id="name" | ||
name="name" | ||
label="Name" | ||
error={f.errors.name} | ||
onChange={f.handleChange} | ||
/> | ||
<InputArea | ||
id="description" | ||
label="Description" | ||
name="description" | ||
onChange={f.handleChange} | ||
error={f.errors.description} | ||
/> | ||
</Flex> | ||
|
||
<Grid gap="2" justify="between" columns="2" width="200px" mb="4"> | ||
<Button | ||
type="button" | ||
color="gray" | ||
variant="outline" | ||
disabled={f.isSubmitting} | ||
onClick={() => navigate(paths.urls.eventTypes)} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
type="submit" | ||
loading={f.isSubmitting} | ||
disabled={f.isSubmitting} | ||
> | ||
Save | ||
</Button> | ||
</Grid> | ||
|
||
{error && <Alert color="red">{error}</Alert>} | ||
</form> | ||
); | ||
} | ||
|
||
function validationSchema() { | ||
return yup.object().shape({ | ||
name: yup.string().required(), | ||
description: yup.string().optional(), | ||
}); | ||
} | ||
|
||
const initialValues = { | ||
name: "", | ||
description: "", | ||
}; |
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