Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/navigation/Navigation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import PropTypes from 'prop-types'
import React from 'react'
import {Menu, MenuItem} from '@dhis2/ui'

// @TODO: Import the `Menu` and `MenuItem` components
import { useNavigate, useMatch } from 'react-router-dom'

Expand All @@ -17,7 +19,7 @@ const NavigationItem = ({ path, label }) => {
const onClick = () => navigate(path)

// @TODO: Use the `MenuItem` component instead of the `div`
return <div>{label}</div>
return <MenuItem active={isActive} label={label} onClick={onClick}></MenuItem>
}

NavigationItem.propTypes = {
Expand All @@ -27,7 +29,7 @@ NavigationItem.propTypes = {

export const Navigation = () => (
// @TODO: Use the `Menu` components instead of the `div`
<div>
<Menu>
<NavigationItem
// Menu item for the home page
label="Home"
Expand All @@ -45,5 +47,5 @@ export const Navigation = () => (
label="Form"
path="/form"
/>
</div>
</Menu>
)
29 changes: 28 additions & 1 deletion src/views/Attributes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import { useGetAttributes } from '../hooks/index.js'
import {Table, TableHead, TableRowHead, TableCellHead, TableBody, TableRow, TableCell, TableFoot} from '@dhis2-ui/table'

export const Attributes = () => {
// we get the data using a custom hook
Expand All @@ -15,7 +16,33 @@ export const Attributes = () => {
// if there is any data available
data?.attributes?.attributes && (
<pre>
{JSON.stringify(data.attributes.attributes, null, 4)}
<Table>
<TableHead>
<TableRowHead>
<TableCellHead>
Name
</TableCellHead>
<TableCellHead>
Unique
</TableCellHead>
</TableRowHead>
</TableHead>
<TableBody>
{data.attributes.attributes.map(attr =>(
<TableRow>
<TableCell>
{attr.displayName}
</TableCell>
<TableCell>
{attr.unique ?"Yes":"No"}
</TableCell>
</TableRow>

))}
</TableBody>

</Table>

</pre>
)
}
Expand Down
104 changes: 100 additions & 4 deletions src/views/Form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ReactFinalForm } from '@dhis2/ui'
import { ReactFinalForm, SingleSelectFieldFF, InputFieldFF, SwitchFieldFF, hasValue, email, composeValidators, Button, createEqualTo, dhis2Username, dhis2Password} from '@dhis2/ui'

import React from 'react'
import styles from './Form.module.css'

Expand All @@ -11,10 +12,12 @@ import styles from './Form.module.css'
* @param {string} values.title
* @param {string} values.surname
* @param {string} values.firstname
* @param {string} values.username
* @param {string} values.email
* @param {string} values.email-confirmation
* @param {bool} values.newsletter
*/

const alertValues = (values) => {
const formattedValuesString = JSON.stringify(values, null, 2)
alert(formattedValuesString)
Expand All @@ -29,15 +32,108 @@ export const Form = () => (
<RFForm onSubmit={alertValues}>
{({ handleSubmit }) => (
<form onSubmit={handleSubmit}>
<div className={styles.row}>
<Field
name="Title"
label="Title"
component={SingleSelectFieldFF}
className={styles.title}
initialValue="a"
options={[
{ label: 'None', value: 'a' },
{ label: 'Professor', value: 'b' },
{ label: 'Doctor', value: 'm' },
]}
/>
</div>
<div className={styles.row}>
<Field
name="surname"
label="Surname"
component={'input'}
label="Surname*"
component={InputFieldFF}
className={styles.surname}
initialValue={'Traore'}
initialValue=""
validate={hasValue}
/>
<Field
name="firstname"
label="firstname*"
component={InputFieldFF}
className={styles.firstname}
initialValue=""
validate={hasValue}
/>
</div>
<div className={styles.row}>
<Field
name="dhis2Username"
label="username*"
component={InputFieldFF}
className={styles.dhis2Username}
initialValue=""
validate={hasValue}
/>

</div>
<div className={styles.row}>
<Field
name="password"
label="password*"
type="password"
component={InputFieldFF}
className={styles.username}
initialValue=""
validate={composeValidators(
dhis2Password,
hasValue
/>

</div>

<div className={styles.row}>
<Field
name="email"
label="E-mail address*"
component={InputFieldFF}
className={styles.email}
initialValue=""
validate={composeValidators(email,hasValue)}
/>
</div>
<div className={styles.row}>
<Field
name="confirm_email"
label="Confirm e-mail address*"
component={InputFieldFF}
className={styles.email}
initialValue=""
validate={composeValidators(createEqualTo("email","",hasValue))}

/>
</div>
<div className={styles.row}>
<Field
name="newsletter"
label="I want to recieve the newsletter*"
type="checkbox"
component={SwitchFieldFF}
className={styles.newsletter}
initialValue=""
validate={hasValue}
/>
</div>
<Button
ariaLabel="Button"
name="Primary button"
type="submit"
primary
title="Button"
value="default"
>
Submit form
</Button>


</form>
)}
</RFForm>
Expand Down
4 changes: 4 additions & 0 deletions src/views/Form.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
flex-grow: 1;
}

.username {
flex-grow: 1;
}

.email {
flex-grow: 1;
}