diff --git a/src/cmn.js b/src/cmn.js new file mode 100644 index 0000000..d067c32 --- /dev/null +++ b/src/cmn.js @@ -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); +} \ No newline at end of file diff --git a/src/components/Add.js b/src/components/Add.js index 5963aa3..50f73c2 100644 --- a/src/components/Add.js +++ b/src/components/Add.js @@ -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); @@ -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); @@ -163,7 +134,7 @@ class AddForm extends React.Component {
{ - languages_str += capitalise(entry[0]) + " (" + entry[1] + "), "; - }) - - return languages_str.slice(0, -2); - } - getExperienceDisplay(experience) { var experience_str = ""; @@ -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)), @@ -438,7 +399,7 @@ class AddForm extends React.Component { Enter levels of need the Coach has experience with.

{ - languages_str += this.capitalize(entry[0]) + " (" + entry[1] + ")\n"; + languages_str += cmn.capitalise(entry[0]) + " (" + entry[1] + ")\n"; }) return languages_str.slice(0, -2); @@ -242,7 +217,7 @@ class AssignForm extends React.Component {
{ - 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]; @@ -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), @@ -493,7 +454,7 @@ class AssignForm extends React.Component { Enter the Member's level of need.