-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
front: adds SendEmailForm and SendEmailButton components
- Loading branch information
1 parent
4746aeb
commit 00dc1f2
Showing
4 changed files
with
95 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {Button, IconEnvelope} from "hds-react"; | ||
|
||
const SendEmailButton = ({...rest}) => ( | ||
<Button | ||
theme="black" | ||
iconLeft={<IconEnvelope />} | ||
{...rest} | ||
> | ||
Lähetä sähköposti | ||
</Button> | ||
); | ||
|
||
export default SendEmailButton; |
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,52 @@ | ||
import {useForm} from "react-hook-form"; | ||
import {Select, TextInput} from "./form"; | ||
import SendEmailButton from "./SendEmailButton"; | ||
|
||
type SendEmailFormProps = { | ||
recipient?: string; | ||
email: string; | ||
options: Array<{value: string; label: string}>; | ||
}; | ||
|
||
const SendEmailForm = ({recipient, email = "", options}: SendEmailFormProps) => { | ||
const sendEmailForm = useForm({ | ||
defaultValues: { | ||
email: email, | ||
template: 0, | ||
}, | ||
mode: "all", | ||
}); | ||
const {handleSubmit} = sendEmailForm; | ||
const sendEmail = (data) => { | ||
// Validation & implement sending email still missing | ||
// eslint-disable-next-line no-console | ||
console.log("Sending email", data); | ||
}; | ||
return ( | ||
<form | ||
className="send-email-form" | ||
onSubmit={handleSubmit(sendEmail)} | ||
> | ||
<TextInput | ||
name="email" | ||
label={recipient ? recipient + "n sähköpostiosoite" : "Vastaanottajan sähköpostiosoite"} | ||
formObject={sendEmailForm} | ||
tooltipText="Käyttää oletuksena relevanttia sähköpostiosoitetta." | ||
required | ||
/> | ||
<div className="row row--buttons"> | ||
<Select | ||
label="Sähköpostipohja" | ||
options={options} | ||
defaultValue={options[0]} | ||
name="template" | ||
formObject={sendEmailForm} | ||
required | ||
/> | ||
<SendEmailButton type="submit" /> | ||
</div> | ||
</form> | ||
); | ||
}; | ||
|
||
export default SendEmailForm; |
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