Skip to content

Commit

Permalink
CORE-4518: steps
Browse files Browse the repository at this point in the history
  • Loading branch information
ekachxaidze98 committed Nov 29, 2023
1 parent d1f8fcb commit 170c6c4
Show file tree
Hide file tree
Showing 5 changed files with 348 additions and 11 deletions.
27 changes: 27 additions & 0 deletions data/benefits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ HowTo:

join:
title: Join CORE as a data provider and contribute to the creation of a mutually beneficial ecosystem.
description: We have created a [data provider’s]() guide describing best practices of how to expose metadata to CORE. This guide serves as a reference to our data providers.
picture: /images/benefits/join-core.svg
action: join
subOai: If you don’t know the OAI base URL of the data provider, insert the URL of it and we will try to find it.

joinModal:
title: Tell us about yourself
Expand All @@ -206,3 +209,27 @@ services:
action:
- title: Find out more
url: services/repository-dashboard

secondStep:
title: New data provider registration
picture: /images/benefits/join-core.svg
member:
subTitle: This data provider already exist
description: |
You can find data provider’s content at [core.ac.uk/search?q=repository:id={{dataProvider.id}}](). Also here you can find [{{dataProvider.id}}]() profile page on the CORE website.
**Please note**, that if you have submitted this repository recently it may not appear on the search results. Please wait until harvesting will be completed. [Find out more]().
newMember:
subTitle: Thank you for registering a new data provider
description: |
We will review your request to add this data provider to CORE. If this request is successful, we will index the content from this data provider and send you an email when completed. This can take up to **three weeks** depending on the size of the data provider and our workload.
Once completed, if you are an authorised representative of this data provider, we encourage you to become a [CORE Member](/membership) and obtain access to the [CORE Dashboard](/services/repository-dashboard).
issue:
subTitle: OAI is not found
description: |
Please check that given OAI based URL is **correct.**
Example: -https://oro.open.ac.uk/cgi/oai2-
If you believe that your OAI is correct, [contact us](/about#contact) to add it manually.
174 changes: 174 additions & 0 deletions design-v2/benefits/benefitsForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import React, { useState, useEffect } from 'react'
import { Button, Modal, TextField } from '@oacore/design/lib'

import styles from './styles.module.scss'
import generateFormMessage from '../../templates/data-providers/utils/generate-form-message'
import { useInput } from '../../hooks'
import fetchDataProviderAdd from '../../api/data-providers'
import BenefitsStep from './benefitsSecondStep'

import benefitsData from 'data/benefits.yml'

export async function checkDataProviders({ params }) {
const { uri, email, setIsDataProviderAddActive, setDataProvidersResponse } =
params

try {
const result = await fetchDataProviderAdd({ uri, email })
// eslint-disable-next-line no-console
console.log(`fetchDataProviderAdd
=> ${JSON.stringify(result)}`) // Debug
setIsDataProviderAddActive(true)
setDataProvidersResponse(result)
} catch (errorWithDataProvider) {
setIsDataProviderAddActive(true)
setDataProvidersResponse({
error: errorWithDataProvider,
existingDataProviders: [],
})
return {
props: {
error: errorWithDataProvider,
},
notFound: true,
}
}
return true
}

const BenefitsForm = React.forwardRef(({ onSubmit, setModalActive }, ref) => {
const [isIsDataProviderAddActive, setIsDataProviderAddActive] =
useState(false)
const [dataProvidersResponse, setDataProvidersResponse] = useState([])
const [modalContent, setModalContent] = useState(null)
const [formSubmitted, setFormSubmitted] = useState(false)

const {
value: uri,
element: elemDataProviderUrl,
bind: bindDataProviderUrl,
} = useInput('', 'data-provider-url')

const {
value: email,
element: elemEmail,
bind: bindEmail,
} = useInput('', 'email')

const onCloseModal = () => {
setModalActive(false)
}
const handleSubmit = async (event) => {
event.preventDefault()

if (onSubmit) await onSubmit(event)
}

const message = generateFormMessage({ dataProvidersResponse })

useEffect(() => {
if (dataProvidersResponse?.error?.status === 500) {
setFormSubmitted(true)
setModalContent(
<BenefitsStep
subTitle={benefitsData.secondStep.issue.subTitle}
description={benefitsData.secondStep.issue.description}
setModalContent={setModalContent}
setFormSubmitted={setFormSubmitted}
onCloseModal={onCloseModal}
/>
)
} else if (dataProvidersResponse?.error?.status === 409) {
setFormSubmitted(true)
setModalContent(
<BenefitsStep
subTitle={benefitsData.secondStep.member.subTitle}
description={benefitsData.secondStep.member.description}
setModalContent={setModalContent}
setFormSubmitted={setFormSubmitted}
onCloseModal={onCloseModal}
/>
)
} else if (dataProvidersResponse?.error?.status === 200) {
setFormSubmitted(true)
setModalContent(
<BenefitsStep
subTitle={benefitsData.secondStep.newMember.subTitle}
description={benefitsData.secondStep.newMember.description}
setModalContent={setModalContent}
setFormSubmitted={setFormSubmitted}
onCloseModal={onCloseModal}
/>
)
}
}, [dataProvidersResponse?.error?.status])

return (
<>
{formSubmitted ? null : (
<Modal
aria-label="Registration-form-modal"
hideManually
className={styles.modalForm}
>
<h6>New data provider registration</h6>
<form ref={ref} onSubmit={handleSubmit}>
<TextField
className={styles.oaiUrl}
id={elemDataProviderUrl}
type="url"
name={elemDataProviderUrl}
label="OAI base URL"
placeholder="For example, http://example.com/cgi/oai2"
value={uri}
helper={isIsDataProviderAddActive && message.helper}
variant={
(isIsDataProviderAddActive && message.variant) || 'normal'
}
statusIcon
required
{...bindDataProviderUrl}
/>
<span className={styles.subDesc}>{benefitsData.join.subOai}</span>
<TextField
id={elemEmail}
name={elemEmail}
value={email}
label="Email"
placeholder="e.g. [email protected]"
type="email"
required
className={styles.textField}
{...bindEmail}
/>
<div className={styles.buttonGroup}>
<Button variant="text" onClick={onCloseModal}>
cancel
</Button>
<Button
className={styles.buttonCustom}
type="submit"
variant="contained"
onClick={() => {
checkDataProviders({
params: {
uri,
email,
setIsDataProviderAddActive,
setDataProvidersResponse,
},
})
}}
>
Submit
</Button>
</div>
</form>
</Modal>
)}
{modalContent}
</>
)
})

export default BenefitsForm
47 changes: 47 additions & 0 deletions design-v2/benefits/benefitsSecondStep.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import { Button, Modal } from '@oacore/design/lib'

import styles from './styles.module.scss'
import { Markdown } from '../../components'

import benefitsData from 'data/benefits.yml'

const BenefitsStep = ({
subTitle,
description,
setModalContent,
setFormSubmitted,
onCloseModal,
}) => {
const test = () => {
setModalContent(false)
setFormSubmitted(false)
onCloseModal()
}

return (
<Modal
aria-label="Registration-form-modal"
hideManually
className={styles.modalStepForm}
>
<h5 className={styles.stepHeader}>{benefitsData.secondStep.title}</h5>
<div className={styles.stepImage}>
<img
src={benefitsData.secondStep.picture}
alt={benefitsData.secondStep.title}
className={styles.image}
/>
</div>
<span className={styles.stepHeader}>{subTitle}</span>
<Markdown className={styles.stepDescription}>{description}</Markdown>
<div className={styles.stepButton}>
<Button onClick={test} color="primary" outline>
close
</Button>
</div>
</Modal>
)
}

export default BenefitsStep
27 changes: 21 additions & 6 deletions design-v2/benefits/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Layout, Section } from '../components'
// TODO: REPLACE OLD COMPONENT
import JoinForm from './joinForm'
import GratitudeModal from './GratitudeModal'
// TODO: REPLACE OLD COMPONENT
import BenefitsForm from './benefitsForm'

import { Accordion, Content, Markdown } from 'components'
import benefitsData from 'data/benefits.yml'
Expand Down Expand Up @@ -57,11 +59,16 @@ const BenefitsPageTemplate = () => {
const [showAll, setShowAll] = useState(false)
const [showModal, setShowModal] = useState(false)
const [showGratitudeModal, setGratitudeModal] = useState(false)
const [modalActive, setModalActive] = useState(false)

const toggleShowAll = () => {
setShowAll((prev) => !prev)
}

const toggleModal = () => {
setModalActive(true)
}

const itemsToShow = showAll
? faqData.sections[0].items
: faqData.sections[0].items.slice(0, 3)
Expand Down Expand Up @@ -168,12 +175,6 @@ const BenefitsPageTemplate = () => {
<Section id="join-core" caption="join-core" className={styles.joinCore}>
<div className={styles.formBlock}>
<div id="add-new-data-provider" className={styles.addDataProvider}>
<p className={styles.addDataProviderText}>
{benefitsData.join.title}
</p>
<Button onClick={() => setShowModal(true)} variant="contained">
JOIN NOW
</Button>
<JoinForm
visibleModal={showModal}
setGratitudeModal={setGratitudeModal}
Expand All @@ -183,6 +184,19 @@ const BenefitsPageTemplate = () => {
showGratitudeModal={showGratitudeModal}
setGratitudeModal={setGratitudeModal}
/>
<h5>{benefitsData.join.title}</h5>
<Markdown className={styles.benefitsDescription}>
{benefitsData.join.description}
</Markdown>
<Button
className={styles.benefitsJoin}
variant="contained"
tag="a"
onClick={toggleModal}
>
{benefitsData.join.action}
</Button>
{/* <AddDataProviderForm /> */}
</div>
</div>
<div className={styles.imgBlock}>
Expand All @@ -193,6 +207,7 @@ const BenefitsPageTemplate = () => {
/>
</div>
</Section>
{modalActive && <BenefitsForm setModalActive={setModalActive} />}
<Section id="services">
<div className={styles.serviceWrapper}>
{benefitsData.services.map((service) => (
Expand Down
Loading

0 comments on commit 170c6c4

Please sign in to comment.