Skip to content

Commit

Permalink
Merge pull request #22 from jacksonriley/master
Browse files Browse the repository at this point in the history
Move common code into its own file
  • Loading branch information
jacksonriley authored Jan 4, 2021
2 parents 26489c0 + e8af9e3 commit 85b677d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 94 deletions.
42 changes: 42 additions & 0 deletions src/cmn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Common module for shared constants/functions

export const levelOfNeedOpts = [
{"type": 1, "desc": "1 - No intervention necessary"},
{"type": 2, "desc": "2 - Signpost to other resources"},
{"type": 3, "desc": "3 - Information, advice and guidance (IAG)"},
{"type": 4, "desc": "4 - Coaching and skills"},
{"type": 5, "desc": "5 - Coaching engagement skills"},
{"type": 6, "desc": "6 - Intensive support needed"},
]

export const rightsStatusOpts = [
{"type": 1, "desc": "1 - No intervention necessary"},
{"type": 2, "desc": "2 - No recourse to public funds"},
]

export const housingStatusOpts = [
{"type": 1, "desc": "1 - No intervention necessary"},
{"type": 2, "desc": "2 - At risk"},
{"type": 3, "desc": "3 - Unsuitable temporary accommodation"},
{"type": 4, "desc": "4 - Rough sleeping"},
]

export const langProficiencyOpts = [
{"type": 1, "desc": "1 - Good"},
{"type": 2, "desc": "2 - Bad"},
{"type": 3, "desc": "3 - Ugly"},
]

export function capitalise(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}

export function getLanguagesDisplay(languages) {
var languages_str = "";

Object.entries(languages).forEach((entry) => {
languages_str += capitalise(entry[0]) + " (" + entry[1] + "), ";
})

return languages_str.slice(0, -2);
}
55 changes: 8 additions & 47 deletions src/components/Add.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,13 @@ import { confirmAlert } from 'react-confirm-alert';
import Loader from 'react-loader-spinner';
//import 'react-confirm-alert/src/react-confirm-alert.css';

const levelOfNeedOpts = [
{"type": 1, "desc": "1 - No intervention necessary"},
{"type": 2, "desc": "2 - Signpost to other resources"},
{"type": 3, "desc": "3 - Information, advice and guidance (IAG)"},
{"type": 4, "desc": "4 - Coaching and skills"},
{"type": 5, "desc": "5 - Coaching engagement skills"},
{"type": 6, "desc": "6 - Intensive support needed"},
]

const rightsStatusOpts = [
{"type": 1, "desc": "1 - No intervention necessary"},
{"type": 2, "desc": "2 - No recourse to public funds"},
]

const housingStatusOpts = [
{"type": 1, "desc": "1 - No intervention necessary"},
{"type": 2, "desc": "2 - At risk"},
{"type": 3, "desc": "3 - Unsuitable temporary accommodation"},
{"type": 4, "desc": "4 - Rough sleeping"},
]

const langProficiencyOpts = [
{"type": 1, "desc": "1 - Good"},
{"type": 2, "desc": "2 - Bad"},
{"type": 3, "desc": "3 - Ugly"},
]
import * as cmn from "../cmn.js";

const displays = {
FORM: "form",
LOADING: "loading",
}

function capitalise(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}

export default class Add extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -120,7 +91,7 @@ function AddLoader(props) {
)
}

class AddForm extends React.Component {
export class AddForm extends React.Component {
constructor(props) {
super(props);
this.renderLanguageProficiencies = this.renderLanguageProficiencies.bind(this);
Expand Down Expand Up @@ -163,7 +134,7 @@ class AddForm extends React.Component {
</div>
<div className="proficiency-choice">
<Multiselect
options={langProficiencyOpts}
options={cmn.langProficiencyOpts}
displayValue="desc"
closeIcon="cancel"
placeholder="Select Proficiency"
Expand All @@ -180,16 +151,6 @@ class AddForm extends React.Component {
return languageFragments;
}

getLanguagesDisplay() {
var languages_str = "";

Object.entries(this.state.languages).forEach((entry) => {
languages_str += capitalise(entry[0]) + " (" + entry[1] + "), ";
})

return languages_str.slice(0, -2);
}

getExperienceDisplay(experience) {
var experience_str = "";

Expand All @@ -210,9 +171,9 @@ class AddForm extends React.Component {
title: 'Confirm Coach Details',
message: ('First name: ' + this.state.name +
'\nBirth year: ' + this.state.birthYear +
'\nGender: ' + capitalise(this.state.gender) +
'\nGender: ' + cmn.capitalise(this.state.gender) +
'\nAvailability: ' + (this.state.available ? 'Available' : 'Not available') +
'\nLanguages: ' + this.getLanguagesDisplay(this.state.languages) +
'\nLanguages: ' + cmn.getLanguagesDisplay(this.state.languages) +
'\nExperience in Level of Need: ' + this.getExperienceDisplay(this.state.needLevels) +
'\nExperience in Rights Status: ' + this.getExperienceDisplay(this.state.rightsLevels) +
'\nExperience in Housing Status: ' + this.getExperienceDisplay(this.state.housingLevels)),
Expand Down Expand Up @@ -438,7 +399,7 @@ class AddForm extends React.Component {
Enter levels of need the Coach has experience with.
</p>
<Multiselect
options={levelOfNeedOpts}
options={cmn.levelOfNeedOpts}
displayValue="desc"
onSelect={this.onNeedChange}
onRemove={this.onNeedChange}
Expand All @@ -453,7 +414,7 @@ class AddForm extends React.Component {
Enter the rights statuses the Coach has experience with.
</p>
<Multiselect
options={rightsStatusOpts}
options={cmn.rightsStatusOpts}
displayValue="desc"
onSelect={this.onRightsChange}
onRemove={this.onRightsChange}
Expand All @@ -468,7 +429,7 @@ class AddForm extends React.Component {
Enter the housing statuses the Coach has experience with.
</p>
<Multiselect
options={housingStatusOpts}
options={cmn.housingStatusOpts}
displayValue="desc"
onSelect={this.onHousingChange}
onRemove={this.onHousingChange}
Expand Down
55 changes: 8 additions & 47 deletions src/components/Assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,7 @@ import "react-loader-spinner/dist/loader/css/react-spinner-loader.css"
// @@@ Used in testing
//const dummyResults = [{"id":0,"name":"Bob","bio":"Hey, Bob here.","available":true,"birth_year":1992,"gender":"male","languages":{"english":1,"spanish":4},"need":[1,2,3],"rights":[2],"housing":[3],"match_score":35},{"id":4,"name":"Mike","bio":"","available":true,"birth_year":1970,"gender":"male","languages":{"spanish":1,"french":2},"need":[1,2,3],"rights":[2],"housing":[3],"match_score":5},{"id":1,"name":"Albert","bio":"","available":true,"birth_year":1990,"gender":"other","languages":{},"need":[1,2,3],"rights":[2],"housing":[3],"match_score":5},{"id":2,"name":"Kelly S.","bio":"","available":true,"birth_year":1988,"gender":"female","languages":{},"need":[1,2,3],"rights":[2],"housing":[3],"match_score":4}]

const levelOfNeedOpts = [
{"type": 1, "desc": "1 - No intervention necessary"},
{"type": 2, "desc": "2 - Signpost to other resources"},
{"type": 3, "desc": "3 - Information, advice and guidance (IAG)"},
{"type": 4, "desc": "4 - Coaching and skills"},
{"type": 5, "desc": "5 - Coaching engagement skills"},
{"type": 6, "desc": "6 - Intensive support needed"},
]

const rightsStatusOpts = [
{"type": 1, "desc": "1 - No intervention necessary"},
{"type": 2, "desc": "2 - No recourse to public funds"},
]

const housingStatusOpts = [
{"type": 1, "desc": "1 - No intervention necessary"},
{"type": 2, "desc": "2 - At risk"},
{"type": 3, "desc": "3 - Unsuitable temporary accommodation"},
{"type": 4, "desc": "4 - Rough sleeping"},
]

const langProficiencyOpts = [
{"type": 1, "desc": "1 - Good"},
{"type": 2, "desc": "2 - Bad"},
{"type": 3, "desc": "3 - Ugly"},
]
import * as cmn from "../cmn.js";

const displays = {
FORM: "form",
Expand Down Expand Up @@ -171,7 +146,7 @@ class AssignResults extends React.Component {
var languages_str = "";

Object.entries(languages).forEach((entry) => {
languages_str += this.capitalize(entry[0]) + " (" + entry[1] + ")\n";
languages_str += cmn.capitalise(entry[0]) + " (" + entry[1] + ")\n";
})

return languages_str.slice(0, -2);
Expand Down Expand Up @@ -242,7 +217,7 @@ class AssignForm extends React.Component {
</div>
<div className="proficiency-choice">
<Multiselect
options={langProficiencyOpts}
options={cmn.langProficiencyOpts}
displayValue="desc"
closeIcon="cancel"
placeholder="Select Proficiency"
Expand All @@ -259,20 +234,6 @@ class AssignForm extends React.Component {
return languageFragments;
}

getLanguagesDisplay() {
var languages_str = "";

Object.entries(this.state.languages).forEach((entry) => {
languages_str += this.capitalize(entry[0]) + " (" + entry[1] + "), ";
})

return languages_str.slice(0, -2);
}

capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}

format = function() {
var s = arguments[0];

Expand Down Expand Up @@ -317,8 +278,8 @@ class AssignForm extends React.Component {
confirmAlert({
title: 'Confirm Member Details',
message: ('Year of Birth: ' + this.state.year +
'\nGender: ' + this.capitalize(this.state.gender) +
'\nLanguages: ' + this.getLanguagesDisplay() +
'\nGender: ' + cmn.capitalise(this.state.gender) +
'\nLanguages: ' + cmn.getLanguagesDisplay(this.state.languages) +
'\nLevel of Need: ' + this.state.need +
'\nRights Status: ' + this.state.rights +
'\nHousing Status: ' + this.state.housing),
Expand Down Expand Up @@ -493,7 +454,7 @@ class AssignForm extends React.Component {
Enter the Member's level of need.
</p>
<Multiselect
options={levelOfNeedOpts}
options={cmn.levelOfNeedOpts}
displayValue="desc"
closeIcon="cancel"
placeholder="Select Level of Need"
Expand All @@ -508,7 +469,7 @@ class AssignForm extends React.Component {
Enter the Member's rights status.
</p>
<Multiselect
options={rightsStatusOpts}
options={cmn.rightsStatusOpts}
displayValue="desc"
closeIcon="cancel"
placeholder="Select Rights Status"
Expand All @@ -523,7 +484,7 @@ class AssignForm extends React.Component {
Enter the Member's housing status.
</p>
<Multiselect
options={housingStatusOpts}
options={cmn.housingStatusOpts}
displayValue="desc"
closeIcon="cancel"
placeholder="Select Housing Status"
Expand Down

0 comments on commit 85b677d

Please sign in to comment.