-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from KTH/issues/KUI-1374-add-heading-recommen…
…ded-prerequisites Recommended prerequisites now has its own page with editable fields
- Loading branch information
Showing
23 changed files
with
482 additions
and
17 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
47 changes: 47 additions & 0 deletions
47
public/js/app/pages/RecommendedPrerequisitesPage/RecommendedPrerequisitesPage.jsx
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 React from 'react' | ||
|
||
import i18n from '../../../../../i18n' | ||
import PageTitle from '../../components/PageTitle' | ||
import KoppsErrorPage from '../../components/KoppsErrorPage' | ||
import ProgressBar, { useProgressBar } from '../../components-shared/ProgressBar' | ||
import { useWebContextTextInput } from '../../components/WebContextTextInput/useWebContextTextInput' | ||
import { useWebContext } from '../../context/WebContext' | ||
import RecommendedPrerequisitesTextEdit from './components/RecommendedPrerequisitesTextEdit' | ||
import RecommendedPrerequisitesPreview from './components/RecommendedPrerequisitesPreview' | ||
|
||
const useRecommendedPrerequisitesPageState = steps => { | ||
const [context] = useWebContext() | ||
const progress = useProgressBar(steps) | ||
const textInput = useWebContextTextInput() | ||
|
||
const { courseCode } = context.routeData.courseData | ||
const { hasChanges } = textInput | ||
|
||
return { progress, textInput, hasChanges, courseCode } | ||
} | ||
|
||
/** | ||
* Page for editing recommended prerequisites | ||
*/ | ||
function RecommendedPrerequisitesPage() { | ||
const [context] = useWebContext() | ||
const labels = i18n.messages[context.langIndex].editRecommendedPrerequisites | ||
const pageState = useRecommendedPrerequisitesPageState([labels.step1, labels.step2]) | ||
const pageTitleProps = { courseTitleData: context.routeData.courseData, pageTitle: labels.pageHeader } | ||
|
||
if (context.koppsApiError) { | ||
return <KoppsErrorPage pageTitleProps={pageTitleProps} /> | ||
} | ||
|
||
return ( | ||
<div className="kursinfo-main-page"> | ||
<PageTitle {...pageTitleProps} /> | ||
<ProgressBar {...pageState.progress} /> | ||
|
||
{pageState.progress.current === 0 && <RecommendedPrerequisitesTextEdit pageState={pageState} />} | ||
{pageState.progress.current === 1 && <RecommendedPrerequisitesPreview pageState={pageState} />} | ||
</div> | ||
) | ||
} | ||
|
||
export { RecommendedPrerequisitesPage } |
70 changes: 70 additions & 0 deletions
70
.../js/app/pages/RecommendedPrerequisitesPage/components/RecommendedPrerequisitesPreview.jsx
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,70 @@ | ||
import React from 'react' | ||
|
||
import i18n from '../../../../../../i18n' | ||
import Alert from '../../../components-shared/Alert' | ||
import ControlButtons from '../../../components/ControlButtons' | ||
import { useWebContext } from '../../../context/WebContext' | ||
import { goToAdminStartPage } from '../../../util/links' | ||
|
||
import RecommendedPrerequisitesPreviewSection from './RecommendedPrerequisitesPreviewSection' | ||
|
||
export default function RecommendedPrerequisitesPreview({ pageState }) { | ||
const [context] = useWebContext() | ||
const textInputValues = pageState.textInput.values | ||
const { courseCode } = pageState | ||
const texts = i18n.messages[context.langIndex].editRecommendedPrerequisites.step2 | ||
const apiErrorMsg = i18n.messages[context.langIndex].pageTitles.alertMessages.api_error | ||
|
||
const [submitState, setSubmitState] = React.useState({ | ||
inProgress: false, | ||
isError: false, | ||
}) | ||
|
||
async function onConfirm() { | ||
setSubmitState({ | ||
inProgress: true, | ||
isError: false, | ||
}) | ||
try { | ||
await context.doUpsertRecommendedPrerequisites(courseCode, textInputValues) | ||
goToAdminStartPage(courseCode, context.lang, 'pub') | ||
} catch (err) { | ||
setSubmitState({ | ||
inProgress: false, | ||
isError: true, | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
<h2>{texts.header}</h2> | ||
|
||
<RecommendedPrerequisitesPreviewSection | ||
header={texts.fields.recommendedPrerequisitesSv} | ||
value={textInputValues.recommendedPrerequisitesSv} | ||
/> | ||
<RecommendedPrerequisitesPreviewSection | ||
header={texts.fields.recommendedPrerequisitesEn} | ||
value={textInputValues.recommendedPrerequisitesEn} | ||
/> | ||
|
||
{submitState.isError && ( | ||
<Alert type="warning"> | ||
<p>{apiErrorMsg}</p> | ||
</Alert> | ||
)} | ||
|
||
<ControlButtons | ||
pageState={pageState} | ||
back={{ label: texts.backButton }} | ||
next={{ | ||
confirmPublish: true, | ||
onClick: onConfirm, | ||
disabled: submitState.inProgress, | ||
label: texts.nextButton, | ||
}} | ||
/> | ||
</div> | ||
) | ||
} |
10 changes: 10 additions & 0 deletions
10
.../pages/RecommendedPrerequisitesPage/components/RecommendedPrerequisitesPreviewSection.jsx
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,10 @@ | ||
import React from 'react' | ||
|
||
const RecommendedPrerequisitesPreviewSection = ({ header, value }) => ( | ||
<div className="PreviewSection"> | ||
<h3>{header}</h3> | ||
<div>{value && <div className="PreviewSection__textBlock" dangerouslySetInnerHTML={{ __html: value }} />}</div> | ||
</div> | ||
) | ||
|
||
export default RecommendedPrerequisitesPreviewSection |
43 changes: 43 additions & 0 deletions
43
...js/app/pages/RecommendedPrerequisitesPage/components/RecommendedPrerequisitesTextEdit.jsx
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,43 @@ | ||
import React from 'react' | ||
|
||
import i18n from '../../../../../../i18n' | ||
import Alert from '../../../components-shared/Alert' | ||
import ControlButtons from '../../../components/ControlButtons' | ||
import EditorSection from '../../../components/Editor/EditorSection' | ||
import { useWebContext } from '../../../context/WebContext' | ||
|
||
export default function RecommendedPrerequisitesTextEdit({ pageState }) { | ||
const [context] = useWebContext() | ||
const texts = i18n.messages[context.langIndex].editRecommendedPrerequisites.step1 | ||
const { hasErrors, getEditorSectionProps } = pageState.textInput | ||
|
||
const onNext = () => { | ||
if (!hasErrors) pageState.progress.goToNext() | ||
} | ||
|
||
return ( | ||
<form> | ||
<h2>{texts.title}</h2> | ||
|
||
<Alert type="info">{texts.alert}</Alert> | ||
|
||
<EditorSection | ||
title={texts.fields.recommendedPrerequisitesSv} | ||
{...getEditorSectionProps('recommendedPrerequisitesSv')} | ||
/> | ||
<EditorSection | ||
title={texts.fields.recommendedPrerequisitesEn} | ||
{...getEditorSectionProps('recommendedPrerequisitesEn')} | ||
/> | ||
|
||
<ControlButtons | ||
pageState={pageState} | ||
next={{ | ||
onClick: onNext, | ||
disabled: hasErrors, | ||
label: texts.nextButton, | ||
}} | ||
/> | ||
</form> | ||
) | ||
} |
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,3 @@ | ||
import { RecommendedPrerequisitesPage } from './RecommendedPrerequisitesPage' | ||
|
||
export default RecommendedPrerequisitesPage |
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
Oops, something went wrong.