@dcrackel/hematournamentui 1.0.708 → 1.0.710

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +148 -106
  2. package/dist/HemaTournamentUI-lib.es.js +6678 -6196
  3. package/dist/HemaTournamentUI-lib.umd.js +27 -27
  4. package/dist/hematournamentui-tailwind.css +16 -6
  5. package/package.json +1 -1
  6. package/src/stories/Atoms/Input/BaseInput.test.js +97 -85
  7. package/src/stories/Atoms/Input/BaseInput.vue +149 -150
  8. package/src/stories/Organisms/ComplexInputs/ImageCropper/ImageCropper.stories.js +31 -20
  9. package/src/stories/Organisms/ComplexInputs/ImageCropper/ImageCropper.test.js +109 -0
  10. package/src/stories/Organisms/ComplexInputs/ImageCropper/ImageCropper.vue +192 -133
  11. package/src/stories/Organisms/Wizards/EditEventWizard/BasicEventInfo/BasicEventInfo.stories.js +48 -41
  12. package/src/stories/Organisms/Wizards/EditEventWizard/BasicEventInfo/BasicEventInfo.vue +227 -206
  13. package/src/stories/Organisms/Wizards/EditEventWizard/DirectElimination/DirectElimination.vue +226 -225
  14. package/src/stories/Organisms/Wizards/EditEventWizard/DirectEliminationPromotion/DirectEliminationPromotion.vue +204 -204
  15. package/src/stories/Organisms/Wizards/EditEventWizard/EditEventWizard.stories.js +133 -91
  16. package/src/stories/Organisms/Wizards/EditEventWizard/EditEventWizard.test.js +191 -0
  17. package/src/stories/Organisms/Wizards/EditEventWizard/EditEventWizard.vue +366 -309
  18. package/src/stories/Organisms/Wizards/EditEventWizard/EventCustomization/EventCustomization.vue +172 -171
  19. package/src/stories/Organisms/Wizards/EditEventWizard/PoolConfiguration/PoolConfiguration.vue +216 -215
  20. package/src/stories/Organisms/Wizards/EditEventWizard/PriceFields.test.js +79 -0
  21. package/src/stories/Templates/EventManagement/EditEventInfo/EditEventInfo.stories.js +93 -52
  22. package/src/stories/Templates/EventManagement/EditEventInfo/EditEventInfo.vue +91 -75
  23. package/src/stories/Templates/PersonManagement/Admin/Administration/Administration.stories.js +14 -0
  24. package/src/stories/Templates/PersonManagement/Admin/Administration/Administration.test.js +39 -0
  25. package/src/stories/Templates/PersonManagement/Admin/Administration/Administration.vue +13 -3
  26. package/src/stories/Templates/PersonManagement/Basic/BasicEdit.vue +170 -172
  27. package/src/stories/Templates/PersonManagement/PersonManagement.stories.js +156 -103
  28. package/src/stories/Templates/PersonManagement/PersonManagement.test.js +329 -0
  29. package/src/stories/Templates/PersonManagement/PersonManagement.vue +329 -213
  30. package/src/stories/Templates/PersonManagement/PersonManagementDraft.js +42 -0
  31. package/src/stories/Templates/TournamentManagement/TournamentManagement.stories.js +84 -83
  32. package/src/stories/Templates/TournamentManagement/TournamentManagement.test.js +89 -0
  33. package/src/stories/Templates/TournamentManagement/TournamentManagement.vue +363 -360
  34. package/src/stories/Templates/TournamentManagement/TournamentPageOne/TournamentPageOne.stories.js +116 -113
  35. package/src/stories/Templates/TournamentManagement/TournamentPageOne/TournamentPageOne.vue +292 -280
  36. package/src/stories/Util/Validations/PersonManagementValidations.js +45 -29
  37. package/src/stories/Util/Validations/PriceValidation.js +6 -0
  38. package/src/stories/Util/Validations/TournamentFieldsValidations.js +4 -0
@@ -1,280 +1,292 @@
1
- <template>
2
- <section class="w-full">
3
- <div v-if="isNewTournament" class="w-full flex flex-row justify-center">
4
- <BaseText
5
- :color="'quaternary'"
6
- :size="'sm'"
7
- :text="'Step 1 out of 2'"
8
- :weight="'normal'"
9
- data-testid="text-step"
10
- />
11
- </div>
12
- <div class="w-full flex flex-row justify-center my-4">
13
- <BaseText
14
- v-if="isNewTournament"
15
- :color="'primaryHighlight'"
16
- :size="'2xl'"
17
- :text="'Add New Tournament'"
18
- :weight="'normal'"
19
- data-testid="text-add-tournament"
20
- />
21
- <BaseText
22
- v-if="!isNewTournament"
23
- :color="'primaryHighlight'"
24
- :size="'2xl'"
25
- :text="'Basic Tournament Information'"
26
- :weight="'normal'"
27
- data-testid="text-add-tournament"
28
- />
29
- </div>
30
- <div class="w-full flex flex-row justify-center my-4">
31
- <ImageCropper
32
- :urlToImage="tournamentImage"
33
- :uploadImageName="uploadImageName"
34
- :uploadServer="uploadServer"
35
- :imageServer="imageServer"
36
- @update:url="handleNewImageUrl"
37
- />
38
- </div>
39
-
40
- <TitledInput
41
- :inputValue="tournamentName"
42
- :invalid="isFieldInvalid('Name')"
43
- :title="getValidationLabel('Name', 'Tournament Name')"
44
- placeholder="Enter Tournament Name"
45
- @update:value="emitUpdate('Name', $event)"
46
- class="mb-4"
47
- />
48
-
49
- <div class="flex flex-col mb-4">
50
- <BaseText
51
- :color="'primaryHighlight'"
52
- :invalid="isFieldInvalid('Address')"
53
- :text="getValidationLabel('Address', 'Location')"
54
- :size="'sm'"
55
- :weight="'normal'"
56
- class="mb-1"
57
- data-testid="text-address"
58
- />
59
- <FindLocation
60
- :placeholder="addressName"
61
- :addBorder="true"
62
- :locations="locations"
63
- :invalid="isFieldInvalid('Address')"
64
- addNewText="Add New"
65
- @update:location="handleAddressUpdate"
66
- @submit:location="handleAddressUpdate"
67
- @submit:addNewAddress="handleAddNewAddress"
68
- />
69
- </div>
70
-
71
- <div class="flex flex-row mb-4">
72
- <div class="w-3/4 mr-1">
73
- <BaseText
74
- :color="'primaryHighlight'"
75
- :invalid="isFieldInvalid('StartDate')"
76
- :size="'sm'"
77
- :text="getValidationLabel('StartDate', 'Start Date')"
78
- :weight="'normal'"
79
- class="mb-1"
80
- data-testid="text-start-date"
81
- />
82
- <DatePicker
83
- :invalid="isFieldInvalid('StartDate')"
84
- :setDate="startDate"
85
- :userLevel="userLevel"
86
- @update:selectedDate="emitUpdate('StartDate', $event)"
87
- />
88
- </div>
89
- <div>
90
- <TitledInput
91
- :inputValue="totalDays"
92
- :invalid="isFieldInvalid('TotalDays')"
93
- :placeholder="'Number of Days'"
94
- :inputType="'number'"
95
- :title="getValidationLabel('TotalDays', 'Number of Days')"
96
- @update:value="emitUpdate('TotalDays', $event)"
97
- />
98
- </div>
99
- </div>
100
-
101
- <div class="w-full mr-1 mb-4">
102
- <BaseText
103
- :color="'primaryHighlight'"
104
- :invalid="isFieldInvalid('RegistrationCutOff')"
105
- :size="'sm'"
106
- :text="getValidationLabel('RegistrationCutOff', 'Registration Cut Off')"
107
- :weight="'normal'"
108
- class="mb-1"
109
- data-testid="text-start-date"
110
- />
111
- <DatePicker
112
- :invalid="isFieldInvalid('RegistrationCutOff')"
113
- :setDate="registrationCutOff"
114
- :userLevel="userLevel"
115
- @update:selectedDate="emitUpdate('RegistrationCutOff', $event)"
116
- />
117
- </div>
118
-
119
- <div class="flex flex-col mb-4">
120
- <BaseText
121
- :color="'primaryHighlight'"
122
- :invalid="isFieldInvalid('Description')"
123
- :size="'sm'"
124
- :text="getValidationLabel('Description', 'Description')"
125
- :weight="'normal'"
126
- class="mb-1"
127
- data-testid="text-description"
128
- />
129
- <TextBoxEditor
130
- :invalid="isFieldInvalid('Description')"
131
- :initialContent="description"
132
- @update:editorContent="emitUpdate('Description', $event)"
133
- />
134
- </div>
135
-
136
- <div class="flex flex-col pb-4 mr-4">
137
- <BaseText
138
- :color="'primaryHighlight'"
139
- :invalid="false"
140
- :size="'sm'"
141
- :text="'Primary Contact'"
142
- :weight="'normal'"
143
- class="mb-1"
144
- data-testid="text-primary-contact"
145
- />
146
- <FindPerson
147
- :addBorder="true"
148
- :persons="persons"
149
- :defaultValue="getDefaultPerson"
150
- addNewText="Add New Person"
151
- @add-new-person="handleAddNewPerson"
152
- @person-selected="handlePrimaryContactUpdate"
153
- />
154
- </div>
155
- </section>
156
- </template>
157
-
158
- <script>
159
- import TitledInput from '../../../Molecules/CombinationInputs/TitledInput/TitledInput.vue';
160
- import FindLocation from '../../../Organisms/ComplexInputs/FindLocation/FindLocation.vue';
161
- import DatePicker from '../../../Organisms/ComplexInputs/DatePicker/DatePicker.vue';
162
- import BaseText from '../../../Atoms/Text/BaseText.vue';
163
- import TextBoxEditor from '../../../Organisms/ComplexInputs/TextBoxEditor/TextBoxEditor.vue';
164
- import ImageCropper from '../../../Organisms/ComplexInputs/ImageCropper/ImageCropper.vue';
165
- import FindPerson from '../../../Organisms/ComplexInputs/FindPerson/FindPerson.vue';
166
-
167
- export default {
168
- name: 'TournamentPageOne',
169
- emits: ['update:tournament', 'update:image', 'update:address', 'add:newAddress', 'add:newPerson'],
170
- props: {
171
- tournament: {
172
- type: Object,
173
- required: true
174
- },
175
- locations: {
176
- type: Array,
177
- required: true
178
- },
179
- persons: {
180
- type: Array,
181
- required: true
182
- },
183
- validation: {
184
- type: Object,
185
- required: true
186
- },
187
- uploadImageName: {
188
- type: String,
189
- default: 't-default-image'
190
- },
191
- uploadServer: {
192
- type: String,
193
- default: ''
194
- },
195
- imageServer: {
196
- type: String,
197
- default: ''
198
- },
199
- isNewTournament: {
200
- type: Boolean,
201
- default: true
202
- },
203
- userLevel: {
204
- type: String,
205
- default: 'Club'
206
- }
207
- },
208
- components: {
209
- FindPerson,
210
- ImageCropper,
211
- BaseText,
212
- DatePicker,
213
- FindLocation,
214
- TitledInput,
215
- TextBoxEditor
216
- },
217
- computed: {
218
- tournamentImage() {
219
- if (this.tournament.Images && this.tournament.Images.length > 0) {
220
- return this.tournament.Images[0].URL;
221
- }
222
- return '';
223
- },
224
- tournamentName() {
225
- return this.tournament?.Name || '';
226
- },
227
- addressName() {
228
- return this.tournament?.Address?.Name || '';
229
- },
230
- startDate() {
231
- return this.tournament?.StartDate || new Date();
232
- },
233
- totalDays() {
234
- return this.tournament?.TotalDays || 1;
235
- },
236
- registrationCutOff() {
237
- return this.tournament?.RegistrationCutOff || new Date();
238
- },
239
- description() {
240
- return this.tournament?.Description || '';
241
- },
242
- getDefaultPerson: function () {
243
- const person = this.persons.find(p => p.PersonId === this.tournament?.PrimaryContactId);
244
- return person ? person.DisplayName : '';
245
- }
246
- },
247
- methods: {
248
- handleNewImageUrl(url) {
249
- this.$emit('update:image', { ImageLink: url });
250
- },
251
- handleAddNewAddress(newAddress) {
252
- this.$emit('add:newAddress', newAddress);
253
- },
254
- handleAddressUpdate(updatedAddress) {
255
- this.$emit('update:address', updatedAddress);
256
- },
257
- handleAddNewPerson(personName) {
258
- this.$emit('add:newPerson', personName);
259
- },
260
- handlePrimaryContactUpdate(person) {
261
- if (!person) return;
262
- this.$emit('update:tournament', { PrimaryContactId: person.PersonId });
263
- },
264
- emitUpdate(field, value) {
265
- this.$emit('update:tournament', { [field]: value });
266
- },
267
- getFieldValidation(field) {
268
- return this.validation?.[field] || { invalid: false, message: '' };
269
- },
270
- isFieldInvalid(field) {
271
- return this.getFieldValidation(field).invalid;
272
- },
273
- getValidationLabel(field, label) {
274
- const fieldValidation = this.getFieldValidation(field);
275
- if (!fieldValidation.invalid) return label;
276
- return `${label} - ${fieldValidation.message}`;
277
- }
278
- }
279
- };
280
- </script>
1
+ <template>
2
+ <section class="w-full">
3
+ <div v-if="isNewTournament" class="w-full flex flex-row justify-center">
4
+ <BaseText
5
+ :color="'quaternary'"
6
+ :size="'sm'"
7
+ :text="'Step 1 out of 2'"
8
+ :weight="'normal'"
9
+ data-testid="text-step"
10
+ />
11
+ </div>
12
+ <div class="w-full flex flex-row justify-center my-4">
13
+ <BaseText
14
+ v-if="isNewTournament"
15
+ :color="'primaryHighlight'"
16
+ :size="'2xl'"
17
+ :text="'Add New Tournament'"
18
+ :weight="'normal'"
19
+ data-testid="text-add-tournament"
20
+ />
21
+ <BaseText
22
+ v-if="!isNewTournament"
23
+ :color="'primaryHighlight'"
24
+ :size="'2xl'"
25
+ :text="'Basic Tournament Information'"
26
+ :weight="'normal'"
27
+ data-testid="text-add-tournament"
28
+ />
29
+ </div>
30
+ <div class="w-full flex flex-row justify-center my-4">
31
+ <ImageCropper
32
+ :urlToImage="tournamentImage"
33
+ :uploadImageName="uploadImageName"
34
+ :uploadServer="uploadServer"
35
+ :imageServer="imageServer"
36
+ @update:url="handleNewImageUrl"
37
+ />
38
+ </div>
39
+
40
+ <TitledInput
41
+ :inputValue="tournamentName"
42
+ :invalid="isFieldInvalid('Name')"
43
+ :title="getValidationLabel('Name', 'Tournament Name')"
44
+ placeholder="Enter Tournament Name"
45
+ @update:value="emitUpdate('Name', $event)"
46
+ class="mb-4"
47
+ />
48
+
49
+ <TitledInput
50
+ :inputValue="basePrice"
51
+ :invalid="isFieldInvalid('BasePrice')"
52
+ :title="getValidationLabel('BasePrice', 'Base Price')"
53
+ placeholder="0.00"
54
+ @update:value="emitUpdate('BasePrice', $event)"
55
+ class="mb-4"
56
+ />
57
+
58
+ <div class="flex flex-col mb-4">
59
+ <BaseText
60
+ :color="'primaryHighlight'"
61
+ :invalid="isFieldInvalid('Address')"
62
+ :text="getValidationLabel('Address', 'Location')"
63
+ :size="'sm'"
64
+ :weight="'normal'"
65
+ class="mb-1"
66
+ data-testid="text-address"
67
+ />
68
+ <FindLocation
69
+ :placeholder="addressName"
70
+ :addBorder="true"
71
+ :locations="locations"
72
+ :invalid="isFieldInvalid('Address')"
73
+ addNewText="Add New"
74
+ @update:location="handleAddressUpdate"
75
+ @submit:location="handleAddressUpdate"
76
+ @submit:addNewAddress="handleAddNewAddress"
77
+ />
78
+ </div>
79
+
80
+ <div class="flex flex-row mb-4">
81
+ <div class="w-3/4 mr-1">
82
+ <BaseText
83
+ :color="'primaryHighlight'"
84
+ :invalid="isFieldInvalid('StartDate')"
85
+ :size="'sm'"
86
+ :text="getValidationLabel('StartDate', 'Start Date')"
87
+ :weight="'normal'"
88
+ class="mb-1"
89
+ data-testid="text-start-date"
90
+ />
91
+ <DatePicker
92
+ :invalid="isFieldInvalid('StartDate')"
93
+ :setDate="startDate"
94
+ :userLevel="userLevel"
95
+ @update:selectedDate="emitUpdate('StartDate', $event)"
96
+ />
97
+ </div>
98
+ <div>
99
+ <TitledInput
100
+ :inputValue="totalDays"
101
+ :invalid="isFieldInvalid('TotalDays')"
102
+ :placeholder="'Number of Days'"
103
+ :inputType="'number'"
104
+ :title="getValidationLabel('TotalDays', 'Number of Days')"
105
+ @update:value="emitUpdate('TotalDays', $event)"
106
+ />
107
+ </div>
108
+ </div>
109
+
110
+ <div class="w-full mr-1 mb-4">
111
+ <BaseText
112
+ :color="'primaryHighlight'"
113
+ :invalid="isFieldInvalid('RegistrationCutOff')"
114
+ :size="'sm'"
115
+ :text="getValidationLabel('RegistrationCutOff', 'Registration Cut Off')"
116
+ :weight="'normal'"
117
+ class="mb-1"
118
+ data-testid="text-start-date"
119
+ />
120
+ <DatePicker
121
+ :invalid="isFieldInvalid('RegistrationCutOff')"
122
+ :setDate="registrationCutOff"
123
+ :userLevel="userLevel"
124
+ @update:selectedDate="emitUpdate('RegistrationCutOff', $event)"
125
+ />
126
+ </div>
127
+
128
+ <div class="flex flex-col mb-4">
129
+ <BaseText
130
+ :color="'primaryHighlight'"
131
+ :invalid="isFieldInvalid('Description')"
132
+ :size="'sm'"
133
+ :text="getValidationLabel('Description', 'Description')"
134
+ :weight="'normal'"
135
+ class="mb-1"
136
+ data-testid="text-description"
137
+ />
138
+ <TextBoxEditor
139
+ :invalid="isFieldInvalid('Description')"
140
+ :initialContent="description"
141
+ @update:editorContent="emitUpdate('Description', $event)"
142
+ />
143
+ </div>
144
+
145
+ <div class="flex flex-col pb-4 mr-4">
146
+ <BaseText
147
+ :color="'primaryHighlight'"
148
+ :invalid="false"
149
+ :size="'sm'"
150
+ :text="'Primary Contact'"
151
+ :weight="'normal'"
152
+ class="mb-1"
153
+ data-testid="text-primary-contact"
154
+ />
155
+ <FindPerson
156
+ :addBorder="true"
157
+ :persons="persons"
158
+ :defaultValue="getDefaultPerson"
159
+ addNewText="Add New Person"
160
+ @add-new-person="handleAddNewPerson"
161
+ @person-selected="handlePrimaryContactUpdate"
162
+ />
163
+ </div>
164
+ </section>
165
+ </template>
166
+
167
+ <script>
168
+ import TitledInput from '../../../Molecules/CombinationInputs/TitledInput/TitledInput.vue';
169
+ import FindLocation from '../../../Organisms/ComplexInputs/FindLocation/FindLocation.vue';
170
+ import DatePicker from '../../../Organisms/ComplexInputs/DatePicker/DatePicker.vue';
171
+ import BaseText from '../../../Atoms/Text/BaseText.vue';
172
+ import TextBoxEditor from '../../../Organisms/ComplexInputs/TextBoxEditor/TextBoxEditor.vue';
173
+ import ImageCropper from '../../../Organisms/ComplexInputs/ImageCropper/ImageCropper.vue';
174
+ import FindPerson from '../../../Organisms/ComplexInputs/FindPerson/FindPerson.vue';
175
+
176
+ export default {
177
+ name: 'TournamentPageOne',
178
+ emits: ['update:tournament', 'update:image', 'update:address', 'add:newAddress', 'add:newPerson'],
179
+ props: {
180
+ tournament: {
181
+ type: Object,
182
+ required: true
183
+ },
184
+ locations: {
185
+ type: Array,
186
+ required: true
187
+ },
188
+ persons: {
189
+ type: Array,
190
+ required: true
191
+ },
192
+ validation: {
193
+ type: Object,
194
+ required: true
195
+ },
196
+ uploadImageName: {
197
+ type: String,
198
+ default: 't-default-image'
199
+ },
200
+ uploadServer: {
201
+ type: String,
202
+ default: ''
203
+ },
204
+ imageServer: {
205
+ type: String,
206
+ default: ''
207
+ },
208
+ isNewTournament: {
209
+ type: Boolean,
210
+ default: true
211
+ },
212
+ userLevel: {
213
+ type: String,
214
+ default: 'Club'
215
+ }
216
+ },
217
+ components: {
218
+ FindPerson,
219
+ ImageCropper,
220
+ BaseText,
221
+ DatePicker,
222
+ FindLocation,
223
+ TitledInput,
224
+ TextBoxEditor
225
+ },
226
+ computed: {
227
+ tournamentImage() {
228
+ if (this.tournament.Images && this.tournament.Images.length > 0) {
229
+ return this.tournament.Images[0].URL;
230
+ }
231
+ return '';
232
+ },
233
+ tournamentName() {
234
+ return this.tournament?.Name || '';
235
+ },
236
+ basePrice() {
237
+ return this.tournament?.BasePrice ?? '';
238
+ },
239
+ addressName() {
240
+ return this.tournament?.Address?.Name || '';
241
+ },
242
+ startDate() {
243
+ return this.tournament?.StartDate || new Date();
244
+ },
245
+ totalDays() {
246
+ return this.tournament?.TotalDays || 1;
247
+ },
248
+ registrationCutOff() {
249
+ return this.tournament?.RegistrationCutOff || new Date();
250
+ },
251
+ description() {
252
+ return this.tournament?.Description || '';
253
+ },
254
+ getDefaultPerson: function () {
255
+ const person = this.persons.find(p => p.PersonId === this.tournament?.PrimaryContactId);
256
+ return person ? person.DisplayName : '';
257
+ }
258
+ },
259
+ methods: {
260
+ handleNewImageUrl(url) {
261
+ this.$emit('update:image', { ImageLink: url });
262
+ },
263
+ handleAddNewAddress(newAddress) {
264
+ this.$emit('add:newAddress', newAddress);
265
+ },
266
+ handleAddressUpdate(updatedAddress) {
267
+ this.$emit('update:address', updatedAddress);
268
+ },
269
+ handleAddNewPerson(personName) {
270
+ this.$emit('add:newPerson', personName);
271
+ },
272
+ handlePrimaryContactUpdate(person) {
273
+ if (!person) return;
274
+ this.$emit('update:tournament', { PrimaryContactId: person.PersonId });
275
+ },
276
+ emitUpdate(field, value) {
277
+ this.$emit('update:tournament', { [field]: value });
278
+ },
279
+ getFieldValidation(field) {
280
+ return this.validation?.[field] || { invalid: false, message: '' };
281
+ },
282
+ isFieldInvalid(field) {
283
+ return this.getFieldValidation(field).invalid;
284
+ },
285
+ getValidationLabel(field, label) {
286
+ const fieldValidation = this.getFieldValidation(field);
287
+ if (!fieldValidation.invalid) return label;
288
+ return `${label} - ${fieldValidation.message}`;
289
+ }
290
+ }
291
+ };
292
+ </script>
@@ -1,29 +1,45 @@
1
- export function validateField(field, value) {
2
- const rules = {
3
- DisplayName: [
4
- { check: v => !v || v.trim().length === 0, message: 'Must have a name.' },
5
- { check: v => v.trim().length < 3, message: 'Must be at least 3 characters.' }
6
- ],
7
- LegalName: [
8
- { check: v => !v || v.trim().length === 0, message: 'Must have a name.' },
9
- { check: v => v.trim().length < 4, message: 'Must be at least 4 characters.' }
10
- ],
11
- EmailAddress: [
12
- { check: v => v && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v), message: 'Must be a valid email address.' }
13
- ],
14
- SelectedClub: [
15
- {
16
- check: v =>
17
- !v ||
18
- (typeof v === 'string' && v.trim().length === 0) ||
19
- (typeof v === 'object' && (!v.text || v.text.trim().length === 0)),
20
- message: 'Please select a Club.'
21
- }
22
- ]
23
- };
24
-
25
- const ruleSet = rules[field] || [];
26
- const failedRule = ruleSet.find(rule => rule.check(value));
27
-
28
- return failedRule ? { invalid: true, message: failedRule.message } : { invalid: false, message: '' };
29
- }
1
+ function isBlankHemaRatingsId(value) {
2
+ return value === undefined || value === null || (typeof value === 'string' && value.trim() === '');
3
+ }
4
+
5
+ function isPositiveIntegerId(value) {
6
+ if (!['string', 'number'].includes(typeof value)) return false;
7
+ if (typeof value === 'string' && !/^\d+$/.test(value.trim())) return false;
8
+ return Number.isSafeInteger(Number(value)) && Number(value) > 0;
9
+ }
10
+
11
+ function isInvalidHemaRatingsId(value) {
12
+ if (isBlankHemaRatingsId(value)) return false;
13
+ return !isPositiveIntegerId(value);
14
+ }
15
+
16
+ export function validateField(field, value) {
17
+ const rules = {
18
+ DisplayName: [
19
+ { check: v => !v || v.trim().length === 0, message: 'Must have a name.' },
20
+ { check: v => v.trim().length < 3, message: 'Must be at least 3 characters.' }
21
+ ],
22
+ LegalName: [
23
+ { check: v => !v || v.trim().length === 0, message: 'Must have a name.' },
24
+ { check: v => v.trim().length < 4, message: 'Must be at least 4 characters.' }
25
+ ],
26
+ EmailAddress: [
27
+ { check: v => v && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v), message: 'Must be a valid email address.' }
28
+ ],
29
+ HemaRatingsId: [{ check: isInvalidHemaRatingsId, message: 'Enter a positive whole-number ID, or leave it blank.' }],
30
+ SelectedClub: [
31
+ {
32
+ check: v =>
33
+ !v ||
34
+ (typeof v === 'string' && v.trim().length === 0) ||
35
+ (typeof v === 'object' && (!v.text || v.text.trim().length === 0)),
36
+ message: 'Please select a Club.'
37
+ }
38
+ ]
39
+ };
40
+
41
+ const ruleSet = rules[field] || [];
42
+ const failedRule = ruleSet.find(rule => rule.check(value));
43
+
44
+ return failedRule ? { invalid: true, message: failedRule.message } : { invalid: false, message: '' };
45
+ }