Skip to content

Commit

Permalink
Moved applyCustomSort into utilities, used it for role selection ques…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
meleongg committed Nov 30, 2023
1 parent 8064f2f commit 7411c1e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
13 changes: 1 addition & 12 deletions src/components/ApplicationForm/BasicInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ETHNICITY_OPTIONS,
PRONOUN_OPTIONS,
} from '../../utility/Constants'
import { creatableDropdownValue, findElement } from '../../utility/utilities'
import { applyCustomSort, creatableDropdownValue, findElement } from '../../utility/utilities'
import Dropdown from '../Input/Dropdown'
import Select from '../Input/Select'
import { TextInput } from '../Input/TextInput'
Expand Down Expand Up @@ -359,17 +359,6 @@ const StyledTextInput = styled(TextInput)`
margin: 0.5em 1em 1em 0;
`

const applyCustomSort = (data, sort) => {
data.sort((a, b) => {
const indexA = sort.indexOf(a[0])
const indexB = sort.indexOf(b[0])

return indexA - indexB
})

return data
}

// form part 1
export default ({ refs, errors, formInputs, onChange }) => (
<>
Expand Down
34 changes: 18 additions & 16 deletions src/components/ApplicationForm/Skills.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import styled from 'styled-components'
import { CONTRIBUTION_ROLE_OPTIONS, copyText } from '../../utility/Constants'
import { applyCustomSort } from '../../utility/utilities'
import { Select, TextArea, TextInput } from '../Input'
import ResumeUploadBtn from '../ResumeUploadBtn'
import { CenteredH1, ErrorMessage, P, QuestionHeading, ErrorSpan as Required } from '../Typography'
Expand Down Expand Up @@ -91,22 +92,23 @@ export default ({ refs, errors, formInputs, onChange, role, handleResume }) => {
</SubHeading>
{errors?.contributionRole && <ErrorMessage>{errors?.contributionRole}</ErrorMessage>}
{formInputs &&
Object.entries(formInputs?.contributionRole)
.sort()
.map(([key, val]) => (
<Select
key={key}
type="checkbox"
label={CONTRIBUTION_ROLE_OPTIONS[key]}
checked={val}
onChange={() =>
onChange({
contributionRole: { ...formInputs.contributionRole, [key]: !val },
})
}
customRef={key === 'vegetarian' ? refs['contributionRoleRef'] : null}
/>
))}
applyCustomSort(
Object.entries(formInputs?.contributionRole),
Object.keys(CONTRIBUTION_ROLE_OPTIONS)
).map(([key, val]) => (
<Select
key={key}
type="checkbox"
label={CONTRIBUTION_ROLE_OPTIONS[key]}
checked={val}
onChange={() =>
onChange({
contributionRole: { ...formInputs.contributionRole, [key]: !val },
})
}
customRef={key === 'vegetarian' ? refs['contributionRoleRef'] : null}
/>
))}
{formInputs?.contributionRole?.other && (
<TextInput
placeholder="Please Specify"
Expand Down
14 changes: 13 additions & 1 deletion src/utility/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// "balanced" (subarrays' lengths differ as less as possible) or
// "even" (all subarrays but the last have the same length):

import { useState, useCallback } from 'react'
import { useCallback, useState } from 'react'

// https://stackoverflow.com/questions/8188548/splitting-a-js-array-into-n-arrays
export const chunkify = (a, n, balanced) => {
Expand Down Expand Up @@ -144,3 +144,15 @@ export const cutString = (string, maxLength) => {
}
return `${string.substring(0, cut)}...`
}

// for multi-select dropdown hacker app questions
export const applyCustomSort = (data, sort) => {
data.sort((a, b) => {
const indexA = sort.indexOf(a[0])
const indexB = sort.indexOf(b[0])

return indexA - indexB
})

return data
}

0 comments on commit 7411c1e

Please sign in to comment.