-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modal to recruit user (airtable) (#30)
* Modal to recruit user (airtable) * airtable: prevent giving a description if 'other' field is not selected * mobile fixes * updates in user recruitment modal * Updated env variable structure * cloudbuild configuration - automatic deployment Co-authored-by: Jorge S. Mendes de Jesus <jorge.mendesdejesus@isric.org>
- Loading branch information
1 parent
d58b3c4
commit 73e0c7e
Showing
16 changed files
with
536 additions
and
13 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,29 @@ | ||
steps: | ||
- id: 'build-image' | ||
name: 'gcr.io/cloud-builders/docker' | ||
args: | ||
- 'build' | ||
- '-t' | ||
- 'eu.gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME/$REPO_NAME:$SHORT_SHA' | ||
- '-t' | ||
- 'eu.gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME/$REPO_NAME:latest' | ||
- '.' | ||
- '-f' | ||
- './Dockerfile' | ||
timeout: 1200s | ||
- id: 'push-to-registry' | ||
name: 'gcr.io/cloud-builders/docker' | ||
args: | ||
- 'push' | ||
- 'eu.gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME/$REPO_NAME' | ||
- id: 'deploy-to-gke' | ||
name: 'gcr.io/cloud-builders/gcloud' | ||
env: | ||
- 'KUBECONFIG=/.kube/config' | ||
entrypoint: 'bash' | ||
args: | ||
- '-c' | ||
- | | ||
gcloud container clusters get-credentials soils-revealed-cluster --project=$PROJECT_ID --zone=europe-west4-a | ||
kubectl set image deployment/$REPO_NAME --namespace=$BRANCH_NAME soils-revealed=eu.gcr.io/$PROJECT_ID/$REPO_NAME/$BRANCH_NAME/$REPO_NAME:$SHORT_SHA | ||
kubectl rollout restart deployment $REPO_NAME --namespace=$BRANCH_NAME |
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 |
---|---|---|
|
@@ -14,3 +14,5 @@ npm-debug.log | |
.editorconfig | ||
.dockerignore | ||
.env | ||
.Dockerfile | ||
.cloudbuild.yaml |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React, { useCallback, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import Modal from 'components/modal'; | ||
|
||
import { createUserEntry, updateUserEntry } from 'utils/airtable'; | ||
|
||
import Step1 from './content/step1'; | ||
import Step2 from './content/step2'; | ||
|
||
import './style.scss'; | ||
|
||
const UserModal = ({ open, onClose }) => { | ||
const [step, setStep] = useState('step1'); | ||
const [userId, setUserId] = useState(null); | ||
const [userData, setUserData] = useState({ | ||
job_role: '', | ||
job_role_description: '', | ||
map_usage: '', | ||
map_usage_description: '', | ||
email: '', | ||
}); | ||
const [userEntryError, setCreateUserEntryError] = useState(null); | ||
|
||
const handleCreateUser = async e => { | ||
e.preventDefault(); | ||
try { | ||
const user = await createUserEntry({ ...userData }); | ||
setUserId(user[0].id); | ||
setStep('step2'); | ||
} catch (e) { | ||
setCreateUserEntryError(e.message); | ||
} | ||
}; | ||
|
||
const handleUpdateUser = async e => { | ||
e.preventDefault(); | ||
try { | ||
await updateUserEntry(userId, userData); | ||
onClose(); | ||
} catch (e) { | ||
setCreateUserEntryError(e.message); | ||
} | ||
}; | ||
|
||
const userDataUpdate = useCallback( | ||
(key, value) => { | ||
if (key === 'job_role_description') { | ||
setUserData({ | ||
...userData, | ||
job_role: 'other', | ||
[key]: value, | ||
}); | ||
} else if (key === 'map_usage_description') { | ||
setUserData({ | ||
...userData, | ||
map_usage: 'other', | ||
[key]: value, | ||
}); | ||
} else setUserData({ ...userData, [key]: value }); | ||
}, | ||
[userData] | ||
); | ||
|
||
return ( | ||
<Modal open={open} onClose={onClose} title="User details" className="c-user-modal"> | ||
{step === 'step1' && ( | ||
<Step1 | ||
key="step1" | ||
user={userId} | ||
userData={userData} | ||
handleUserData={userDataUpdate} | ||
onClick={handleCreateUser} | ||
error={userEntryError} | ||
/> | ||
)} | ||
{step === 'step2' && ( | ||
<Step2 | ||
key="step2" | ||
userData={userData} | ||
handleUserData={userDataUpdate} | ||
onClick={handleUpdateUser} | ||
error={userEntryError} | ||
/> | ||
)} | ||
</Modal> | ||
); | ||
}; | ||
|
||
UserModal.propTypes = { | ||
open: PropTypes.bool.isRequired, | ||
onClose: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default UserModal; |
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,22 @@ | ||
export const userTypeOptions = [ | ||
{ label: 'Academic research', slug: 'Academic research' }, | ||
{ label: 'Government (local, regional or traditional)', slug: 'Government' }, | ||
{ label: 'Private sector', slug: 'Private sector' }, | ||
{ label: 'NGO sector', slug: 'NGO sector' }, | ||
{ label: 'Other [please specify]', slug: 'other', value: '' }, | ||
]; | ||
|
||
export const useTypeOptions = [ | ||
{ label: 'Curiosity', slug: 'Curiosity' }, | ||
{ label: 'Education', slug: 'Education' }, | ||
{ label: 'Research purposes', slug: 'Research purposes' }, | ||
{ label: 'Planning & Land management', slug: 'Planning and land management' }, | ||
{ label: 'Policy-making', slug: 'Policy-making' }, | ||
{ label: 'Impact & Evaluation', slug: 'Impact and evaluation' }, | ||
{ label: 'Other [please specify]', slug: 'other', value: '' }, | ||
]; | ||
|
||
export default { | ||
userTypeOptions, | ||
useTypeOptions, | ||
}; |
Oops, something went wrong.