| 1 |
import { countryList } from '@/constants/countries' |
| 2 |
|
| 3 |
export type ChoicePresetId = |
| 4 |
| 'countries' |
| 5 |
| 'states' |
| 6 |
| 'stateAbbreviations' |
| 7 |
| 'continents' |
| 8 |
| 'gender' |
| 9 |
| 'ageRanges' |
| 10 |
| 'weekdays' |
| 11 |
|
| 12 |
export interface ChoicePresetOption { |
| 13 |
id: string |
| 14 |
label: string |
| 15 |
} |
| 16 |
|
| 17 |
export interface ChoicePreset { |
| 18 |
id: ChoicePresetId |
| 19 |
labelKey: string |
| 20 |
options: ChoicePresetOption[] |
| 21 |
} |
| 22 |
|
| 23 |
const normalizeLabel = (label: string) => label.trim() |
| 24 |
|
| 25 |
const makePresetOptions = (options: string[]) => |
| 26 |
options.map((label) => { |
| 27 |
const normalized = normalizeLabel(label) |
| 28 |
const value = normalized |
| 29 |
.toLowerCase() |
| 30 |
.replace(/[^a-z0-9]+/g, '-') |
| 31 |
.replace(/(^-|-$)/g, '') |
| 32 |
return { |
| 33 |
id: value || normalized, |
| 34 |
label: normalized, |
| 35 |
} |
| 36 |
}) |
| 37 |
|
| 38 |
const usStates = [ |
| 39 |
'Alabama', |
| 40 |
'Alaska', |
| 41 |
'Arizona', |
| 42 |
'Arkansas', |
| 43 |
'California', |
| 44 |
'Colorado', |
| 45 |
'Connecticut', |
| 46 |
'Delaware', |
| 47 |
'District of Columbia', |
| 48 |
'Florida', |
| 49 |
'Georgia', |
| 50 |
'Hawaii', |
| 51 |
'Idaho', |
| 52 |
'Illinois', |
| 53 |
'Indiana', |
| 54 |
'Iowa', |
| 55 |
'Kansas', |
| 56 |
'Kentucky', |
| 57 |
'Louisiana', |
| 58 |
'Maine', |
| 59 |
'Maryland', |
| 60 |
'Massachusetts', |
| 61 |
'Michigan', |
| 62 |
'Minnesota', |
| 63 |
'Mississippi', |
| 64 |
'Missouri', |
| 65 |
'Montana', |
| 66 |
'Nebraska', |
| 67 |
'Nevada', |
| 68 |
'New Hampshire', |
| 69 |
'New Jersey', |
| 70 |
'New Mexico', |
| 71 |
'New York', |
| 72 |
'North Carolina', |
| 73 |
'North Dakota', |
| 74 |
'Ohio', |
| 75 |
'Oklahoma', |
| 76 |
'Oregon', |
| 77 |
'Pennsylvania', |
| 78 |
'Rhode Island', |
| 79 |
'South Carolina', |
| 80 |
'South Dakota', |
| 81 |
'Tennessee', |
| 82 |
'Texas', |
| 83 |
'Utah', |
| 84 |
'Vermont', |
| 85 |
'Virginia', |
| 86 |
'Washington', |
| 87 |
'West Virginia', |
| 88 |
'Wisconsin', |
| 89 |
'Wyoming', |
| 90 |
] |
| 91 |
|
| 92 |
const usStateAbbreviations = [ |
| 93 |
'AL', |
| 94 |
'AK', |
| 95 |
'AZ', |
| 96 |
'AR', |
| 97 |
'CA', |
| 98 |
'CO', |
| 99 |
'CT', |
| 100 |
'DE', |
| 101 |
'DC', |
| 102 |
'FL', |
| 103 |
'GA', |
| 104 |
'HI', |
| 105 |
'ID', |
| 106 |
'IL', |
| 107 |
'IN', |
| 108 |
'IA', |
| 109 |
'KS', |
| 110 |
'KY', |
| 111 |
'LA', |
| 112 |
'ME', |
| 113 |
'MD', |
| 114 |
'MA', |
| 115 |
'MI', |
| 116 |
'MN', |
| 117 |
'MS', |
| 118 |
'MO', |
| 119 |
'MT', |
| 120 |
'NE', |
| 121 |
'NV', |
| 122 |
'NH', |
| 123 |
'NJ', |
| 124 |
'NM', |
| 125 |
'NY', |
| 126 |
'NC', |
| 127 |
'ND', |
| 128 |
'OH', |
| 129 |
'OK', |
| 130 |
'OR', |
| 131 |
'PA', |
| 132 |
'RI', |
| 133 |
'SC', |
| 134 |
'SD', |
| 135 |
'TN', |
| 136 |
'TX', |
| 137 |
'UT', |
| 138 |
'VT', |
| 139 |
'VA', |
| 140 |
'WA', |
| 141 |
'WV', |
| 142 |
'WI', |
| 143 |
'WY', |
| 144 |
] |
| 145 |
|
| 146 |
const continents = [ |
| 147 |
'Africa', |
| 148 |
'Antarctica', |
| 149 |
'Asia', |
| 150 |
'Europe', |
| 151 |
'North America', |
| 152 |
'Oceania', |
| 153 |
'South America', |
| 154 |
] |
| 155 |
|
| 156 |
const genderOptions = ['Female', 'Male', 'Non-binary', 'Prefer not to say'] |
| 157 |
|
| 158 |
const ageRangeOptions = [ |
| 159 |
'Under 18', |
| 160 |
'18-24', |
| 161 |
'25-34', |
| 162 |
'35-44', |
| 163 |
'45-54', |
| 164 |
'55-64', |
| 165 |
'65 or Above', |
| 166 |
'Prefer Not to Answer', |
| 167 |
] |
| 168 |
|
| 169 |
const weekdayOptions = [ |
| 170 |
'Monday', |
| 171 |
'Tuesday', |
| 172 |
'Wednesday', |
| 173 |
'Thursday', |
| 174 |
'Friday', |
| 175 |
'Saturday', |
| 176 |
'Sunday', |
| 177 |
] |
| 178 |
|
| 179 |
export const choicePresets: ChoicePreset[] = [ |
| 180 |
{ |
| 181 |
id: 'countries', |
| 182 |
labelKey: 'bulk_edit_preset_countries', |
| 183 |
options: makePresetOptions(countryList.map((country) => country.name)), |
| 184 |
}, |
| 185 |
{ |
| 186 |
id: 'states', |
| 187 |
labelKey: 'bulk_edit_preset_states', |
| 188 |
options: makePresetOptions(usStates), |
| 189 |
}, |
| 190 |
{ |
| 191 |
id: 'stateAbbreviations', |
| 192 |
labelKey: 'bulk_edit_preset_state_abr', |
| 193 |
options: makePresetOptions(usStateAbbreviations), |
| 194 |
}, |
| 195 |
{ |
| 196 |
id: 'continents', |
| 197 |
labelKey: 'bulk_edit_preset_continents', |
| 198 |
options: makePresetOptions(continents), |
| 199 |
}, |
| 200 |
{ |
| 201 |
id: 'gender', |
| 202 |
labelKey: 'bulk_edit_preset_gender', |
| 203 |
options: makePresetOptions(genderOptions), |
| 204 |
}, |
| 205 |
{ |
| 206 |
id: 'ageRanges', |
| 207 |
labelKey: 'bulk_edit_preset_age', |
| 208 |
options: makePresetOptions(ageRangeOptions), |
| 209 |
}, |
| 210 |
{ |
| 211 |
id: 'weekdays', |
| 212 |
labelKey: 'bulk_edit_preset_days', |
| 213 |
options: makePresetOptions(weekdayOptions), |
| 214 |
}, |
| 215 |
] |
| 216 |
|