Skip to content

Commit

Permalink
refactor: remove containers
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Mar 29, 2023
1 parent 4d98b23 commit 2280887
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 468 deletions.
14 changes: 7 additions & 7 deletions src/components/Routes/Routes.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import React from 'react'
import { Route } from 'react-router-dom'
import { Router } from 'react-router'
import { JobListContainer } from '../../pages/JobList'
import { JobEditContainer } from '../../pages/JobEdit'
import { JobView } from '../../pages/JobView'
import { JobAddContainer } from '../../pages/JobAdd'
import JobList from '../../pages/JobList'
import JobEdit from '../../pages/JobEdit'
import JobView from '../../pages/JobView'
import JobAdd from '../../pages/JobAdd'
import history from '../../services/history'

const Routes = () => (
<Router history={history}>
<Route exact path="/" component={JobListContainer} />
<Route path="/edit/:id" component={JobEditContainer} />
<Route exact path="/" component={JobList} />
<Route path="/edit/:id" component={JobEdit} />
<Route path="/view/:id" component={JobView} />
<Route path="/add" component={JobAddContainer} />
<Route path="/add" component={JobAdd} />
</Router>
)

Expand Down
74 changes: 35 additions & 39 deletions src/pages/JobAdd/JobAdd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react'
import { PropTypes } from '@dhis2/prop-types'
import React, { useState } from 'react'
import { Card, IconInfo16 } from '@dhis2/ui'
import i18n from '@dhis2/d2-i18n'
import { DiscardFormButton } from '../../components/Buttons'
Expand All @@ -9,45 +8,42 @@ import styles from './JobAdd.module.css'
const infoLink =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-236/maintaining-the-system/scheduling.html'

const JobAdd = ({ isPristine, setIsPristine }) => (
<React.Fragment>
<header className={styles.pageHeader}>
<DiscardFormButton
shouldConfirm={!isPristine}
className={styles.pageHeaderButton}
small
>
{i18n.t('Back to all jobs')}
</DiscardFormButton>
<h2 className={styles.pageHeaderTitle}>{i18n.t('New Job')}</h2>
</header>
<Card className={styles.card}>
<header className={styles.cardHeader}>
<h3 className={styles.cardHeaderTitle}>
{i18n.t('Configuration')}
</h3>
<a
href={infoLink}
className={styles.cardHeaderLink}
target="_blank"
rel="noopener noreferrer"
const JobAdd = () => {
const [isPristine, setIsPristine] = useState(true)

return (
<React.Fragment>
<header className={styles.pageHeader}>
<DiscardFormButton
shouldConfirm={!isPristine}
className={styles.pageHeaderButton}
small
>
<span className={styles.cardHeaderInfo}>
<IconInfo16 />
</span>
{i18n.t('About job configuration')}
</a>
{i18n.t('Back to all jobs')}
</DiscardFormButton>
<h2 className={styles.pageHeaderTitle}>{i18n.t('New Job')}</h2>
</header>
<JobAddFormContainer setIsPristine={setIsPristine} />
</Card>
</React.Fragment>
)

const { bool, func } = PropTypes

JobAdd.propTypes = {
isPristine: bool.isRequired,
setIsPristine: func.isRequired,
<Card className={styles.card}>
<header className={styles.cardHeader}>
<h3 className={styles.cardHeaderTitle}>
{i18n.t('Configuration')}
</h3>
<a
href={infoLink}
className={styles.cardHeaderLink}
target="_blank"
rel="noopener noreferrer"
>
<span className={styles.cardHeaderInfo}>
<IconInfo16 />
</span>
{i18n.t('About job configuration')}
</a>
</header>
<JobAddFormContainer setIsPristine={setIsPristine} />
</Card>
</React.Fragment>
)
}

export default JobAdd
13 changes: 0 additions & 13 deletions src/pages/JobAdd/JobAdd.test.js

This file was deleted.

10 changes: 0 additions & 10 deletions src/pages/JobAdd/JobAddContainer.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/pages/JobAdd/JobAddContainer.test.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/pages/JobAdd/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import JobAddContainer from './JobAddContainer'
import JobAdd from './JobAdd'

export { JobAddContainer }
export default JobAdd
137 changes: 74 additions & 63 deletions src/pages/JobEdit/JobEdit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import React from 'react'
import { PropTypes } from '@dhis2/prop-types'
import { Card, IconInfo16 } from '@dhis2/ui'
import React, { useState } from 'react'
import {
CircularLoader,
Layer,
CenteredContent,
Card,
IconInfo16,
} from '@dhis2/ui'
import { useParams } from 'react-router-dom'
import i18n from '@dhis2/d2-i18n'
import { useJobById } from '../../hooks/jobs'
import { DiscardFormButton } from '../../components/Buttons'
import { JobEditFormContainer } from '../../components/Forms'
import { JobDetails } from '../../components/JobDetails'
Expand All @@ -10,68 +17,72 @@ import styles from './JobEdit.module.css'
const infoLink =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-236/maintaining-the-system/scheduling.html'

const JobEdit = ({
isPristine,
setIsPristine,
name,
created,
lastExecutedStatus,
lastExecuted,
}) => (
<React.Fragment>
<header className={styles.pageHeader}>
<DiscardFormButton
shouldConfirm={!isPristine}
className={styles.pageHeaderButton}
small
>
{i18n.t('Back to all jobs')}
</DiscardFormButton>
<h2 className={styles.pageHeaderTitle}>
{i18n.t('Job: {{ name }}', {
name,
nsSeparator: '>',
})}
</h2>
</header>
<Card className={styles.card}>
<header className={styles.cardHeader}>
<h3 className={styles.cardHeaderTitle}>
{i18n.t('Configuration')}
</h3>
<a
href={infoLink}
className={styles.cardHeaderLink}
target="_blank"
rel="noopener noreferrer"
>
<span className={styles.cardHeaderInfo}>
<IconInfo16 />
</span>
{i18n.t('About job configuration')}
</a>
</header>
<div className={styles.jobDetails}>
<JobDetails
created={created}
lastExecutedStatus={lastExecutedStatus}
lastExecuted={lastExecuted}
/>
</div>
<JobEditFormContainer setIsPristine={setIsPristine} />
</Card>
</React.Fragment>
)
const JobEdit = () => {
const [isPristine, setIsPristine] = useState(true)
const { id } = useParams()
const { data, loading, error } = useJobById(id)

if (loading) {
return (
<Layer>
<CenteredContent>
<CircularLoader />
</CenteredContent>
</Layer>
)
}

const { bool, func, string } = PropTypes
if (error) {
throw error
}

JobEdit.propTypes = {
created: string.isRequired,
isPristine: bool.isRequired,
lastExecuted: string.isRequired,
lastExecutedStatus: string.isRequired,
name: string.isRequired,
setIsPristine: func.isRequired,
const { name, created, lastExecutedStatus, lastExecuted } = data

return (
<React.Fragment>
<header className={styles.pageHeader}>
<DiscardFormButton
shouldConfirm={!isPristine}
className={styles.pageHeaderButton}
small
>
{i18n.t('Back to all jobs')}
</DiscardFormButton>
<h2 className={styles.pageHeaderTitle}>
{i18n.t('Job: {{ name }}', {
name,
nsSeparator: '>',
})}
</h2>
</header>
<Card className={styles.card}>
<header className={styles.cardHeader}>
<h3 className={styles.cardHeaderTitle}>
{i18n.t('Configuration')}
</h3>
<a
href={infoLink}
className={styles.cardHeaderLink}
target="_blank"
rel="noopener noreferrer"
>
<span className={styles.cardHeaderInfo}>
<IconInfo16 />
</span>
{i18n.t('About job configuration')}
</a>
</header>
<div className={styles.jobDetails}>
<JobDetails
created={created}
lastExecutedStatus={lastExecutedStatus}
lastExecuted={lastExecuted}
/>
</div>
<JobEditFormContainer setIsPristine={setIsPristine} />
</Card>
</React.Fragment>
)
}

export default JobEdit
17 changes: 0 additions & 17 deletions src/pages/JobEdit/JobEdit.test.js

This file was deleted.

38 changes: 0 additions & 38 deletions src/pages/JobEdit/JobEditContainer.js

This file was deleted.

Loading

0 comments on commit 2280887

Please sign in to comment.