@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
@@ -0,0 +1,109 @@
1
+ import { afterEach, describe, expect, it } from 'vitest';
2
+ import { enableAutoUnmount, mount } from '@vue/test-utils';
3
+ import ImageCropper from './ImageCropper.vue';
4
+
5
+ enableAutoUnmount(afterEach);
6
+
7
+ const mountCropper = props =>
8
+ mount(ImageCropper, {
9
+ props: {
10
+ urlToImage: 'https://images.example/profile.png',
11
+ imageServer: 'https://images.example/',
12
+ uploadImageName: 'profile',
13
+ isProfile: true,
14
+ ...props
15
+ },
16
+ global: { stubs: { AvatarCropper: true } }
17
+ });
18
+
19
+ describe('ImageCropper upload draft events', () => {
20
+ it('emits a successful upload URL and previews it with a fresh cache key', async () => {
21
+ const wrapper = mountCropper({ uploadImageName: 'new-profile' });
22
+ wrapper.vm.handleUploading();
23
+ wrapper.vm.handleUploaded({ response: { status: 201 } });
24
+ await wrapper.vm.$nextTick();
25
+
26
+ expect(wrapper.emitted('update:url')).toEqual([['https://images.example/new-profile.png']]);
27
+ expect(wrapper.emitted('update:uploading')).toEqual([[true], [false]]);
28
+ const preview = new URL(wrapper.find('img').attributes('src'));
29
+ expect(preview.pathname).toBe('/new-profile.png');
30
+ expect(preview.searchParams.has('preview')).toBe(true);
31
+ await wrapper.setProps({ urlToImage: 'https://images.example/new-profile.png' });
32
+ expect(wrapper.find('img').attributes('src')).toBe(preview.href);
33
+ });
34
+
35
+ it('refreshes the preview even when an upload overwrites the existing URL', async () => {
36
+ const wrapper = mountCropper();
37
+ wrapper.vm.handleUploaded({ response: { status: 200 } });
38
+ await wrapper.vm.$nextTick();
39
+ expect(wrapper.find('img').attributes('src')).toContain('/profile.png?preview=');
40
+ expect(wrapper.emitted('update:url')).toEqual([['https://images.example/profile.png']]);
41
+ });
42
+
43
+ it('keeps the previous image and reports unsuccessful responses separately', () => {
44
+ const wrapper = mountCropper();
45
+ wrapper.vm.handleUploading();
46
+ wrapper.vm.handleUploaded({ response: { status: 500 } });
47
+ expect(wrapper.vm.uploading).toBe(false);
48
+ expect(wrapper.vm.localImageUrl).toBe('https://images.example/profile.png');
49
+ expect(wrapper.emitted('update:url')).toBeUndefined();
50
+ expect(wrapper.emitted('error:upload')[0][0]).toMatchObject({ message: 'Image upload failed.', status: 500 });
51
+ });
52
+
53
+ it('reports malformed upload responses without crashing or emitting an edit', () => {
54
+ const wrapper = mountCropper();
55
+ wrapper.vm.handleUploaded(undefined);
56
+ expect(wrapper.emitted('update:url')).toBeUndefined();
57
+ expect(wrapper.emitted('error:upload')).toHaveLength(1);
58
+ });
59
+
60
+ it('rejects unsafe uploaded URLs', () => {
61
+ const wrapper = mountCropper({ imageServer: 'javascript:' });
62
+ wrapper.vm.handleUploaded({ response: { status: 200 } });
63
+ expect(wrapper.emitted('update:url')).toBeUndefined();
64
+ expect(wrapper.emitted('error:upload')[0][0].message).toContain('valid image URL');
65
+ });
66
+
67
+ it('shows a placeholder on image-load failure and leaves the draft URL intact', async () => {
68
+ const wrapper = mountCropper();
69
+ await wrapper.find('img').trigger('error');
70
+ expect(wrapper.emitted('update:url')).toBeUndefined();
71
+ expect(wrapper.emitted('error:load')[0][0]).toMatchObject({ url: 'https://images.example/profile.png' });
72
+ expect(wrapper.find('img').attributes('src')).not.toBe('https://images.example/profile.png');
73
+ expect(wrapper.vm.localImageUrl).toBe('https://images.example/profile.png');
74
+ expect(wrapper.vm.showCropper).toBe(false);
75
+ });
76
+
77
+ it('reconciles authoritative URL changes after a failed preview', async () => {
78
+ const wrapper = mountCropper();
79
+ await wrapper.find('img').trigger('error');
80
+ await wrapper.setProps({ urlToImage: 'https://images.example/confirmed.png' });
81
+ expect(wrapper.find('img').attributes('src')).toBe('https://images.example/confirmed.png');
82
+ });
83
+
84
+ it('reports the cropper upload error and releases the busy state', () => {
85
+ const wrapper = mountCropper();
86
+ wrapper.vm.handleUploading();
87
+ wrapper.vm.handlerError({ type: 'upload', message: 'Upload rejected', context: { response: { status: 413 } } });
88
+ expect(wrapper.emitted('error:upload')).toEqual([[{ message: 'Upload rejected', status: 413 }]]);
89
+ expect(wrapper.vm.uploading).toBe(false);
90
+ expect(wrapper.emitted('update:url')).toBeUndefined();
91
+ });
92
+
93
+ it('reports rejected upload requests and releases the busy state', async () => {
94
+ const wrapper = mountCropper();
95
+ const response = Promise.reject(new Error('Network unavailable'));
96
+ wrapper.vm.handleUploading({ response });
97
+ await wrapper.vm.$nextTick();
98
+ expect(wrapper.vm.uploading).toBe(false);
99
+ expect(wrapper.emitted('error:upload')[0][0].message).toBe('Network unavailable');
100
+ expect(wrapper.emitted('update:url')).toBeUndefined();
101
+ });
102
+
103
+ it('disables the native image selector and guards programmatic opening', () => {
104
+ const wrapper = mountCropper({ disabled: true });
105
+ expect(wrapper.find('button').attributes('disabled')).toBeDefined();
106
+ wrapper.vm.setShowCropper();
107
+ expect(wrapper.vm.showCropper).toBe(false);
108
+ });
109
+ });
@@ -1,133 +1,192 @@
1
- <template>
2
- <section class="flex w-full justify-center">
3
- <img
4
- v-if="!uploading"
5
- :src="displayedUrl"
6
- :class="getClasses"
7
- :style="customStyle"
8
- :alt="displayedUrl"
9
- @error="onImageError"
10
- @click="setShowCropper()"
11
- />
12
- <div v-if="uploading" :class="getSkeletonClass" @error="onImageError" @click="setShowCropper()" />
13
- <avatar-cropper
14
- v-model="showCropper"
15
- :upload-url="`${uploadServer}${uploadImageName}`"
16
- :cropper-options="cropperOptions"
17
- @uploading="handleUploading"
18
- @uploaded="handleUploaded"
19
- @completed="handleCompleted"
20
- @error="handlerError"
21
- />
22
- </section>
23
- </template>
24
-
25
- <script>
26
- import AvatarCropper from 'vue-avatar-cropper';
27
- import SelectAnProfile from '../../../../assets/select-profile.png';
28
- import SelectAnImage from '../../../../assets/select-tournament.png';
29
- import loading from '../../../../assets/loading-spinner.gif';
30
-
31
- export default {
32
- name: 'GenericImageCropper',
33
- emits: ['update:url'],
34
- props: {
35
- urlToImage: {
36
- type: String,
37
- default: SelectAnImage
38
- },
39
- customClass: {
40
- type: String,
41
- default: ''
42
- },
43
- customSkeletonClass: {
44
- type: String,
45
- default: ''
46
- },
47
- customStyle: {
48
- type: Object,
49
- default: () => ({})
50
- },
51
- uploadImageName: {
52
- type: String,
53
- default: 'default-image'
54
- },
55
- uploadServer: {
56
- type: String,
57
- default: ''
58
- },
59
- imageServer: {
60
- type: String,
61
- default: ''
62
- },
63
- isProfile: {
64
- type: Boolean,
65
- default: false
66
- },
67
- cropperOptions: {
68
- type: Object,
69
- default: () => ({
70
- aspectRatio: 3 / 2,
71
- autoCropArea: 1,
72
- viewMode: 1,
73
- movable: true,
74
- zoomable: true
75
- })
76
- }
77
- },
78
- components: {
79
- AvatarCropper
80
- },
81
- data() {
82
- return {
83
- loading,
84
- showCropper: false,
85
- uploading: false,
86
- localImageUrl: this.urlToImage
87
- };
88
- },
89
- computed: {
90
- displayedUrl() {
91
- return this.localImageUrl || (this.isProfile ? SelectAnProfile : SelectAnImage);
92
- },
93
- getClasses() {
94
- return this.customClass
95
- ? this.customClass
96
- : 'h-52 w-80 border-2 border-dashed rounded-lg bg-contain bg-contain bg-center bg-no-repeat';
97
- },
98
- getSkeletonClass() {
99
- return this.customSkeletonClass
100
- ? this.customSkeletonClass
101
- : 'border-2 h-52 w-80 border-dashed rounded-lg bg-quaternaryHighlight animate-pulse';
102
- }
103
- },
104
- methods: {
105
- setShowCropper() {
106
- this.showCropper = true;
107
- },
108
- handleUploading() {
109
- this.uploading = true;
110
- },
111
- handleUploaded(response) {
112
- this.uploading = false;
113
- if (response.response.status === 200) {
114
- this.localImageUrl = `${this.imageServer}${this.uploadImageName}.png`;
115
- this.$emit('update:url', `${this.imageServer}${this.uploadImageName}.png`);
116
- }
117
- },
118
- handleCompleted() {
119
- this.message = 'Upload completed.';
120
- },
121
- handlerError(message, type, xhr) {
122
- console.error(message);
123
- console.error(type);
124
- console.error(xhr);
125
- this.message = 'Oops! Something went wrong...';
126
- },
127
- onImageError() {
128
- this.$emit('update:url', null);
129
- this.showCropper = true;
130
- }
131
- }
132
- };
133
- </script>
1
+ <template>
2
+ <section class="flex w-full justify-center" :aria-busy="uploading" :inert="disabled">
3
+ <button
4
+ v-if="!uploading"
5
+ type="button"
6
+ :disabled="disabled"
7
+ :aria-label="isProfile ? 'Change profile image' : 'Change image'"
8
+ class="flex items-center justify-center"
9
+ @click="setShowCropper"
10
+ >
11
+ <img
12
+ :src="displayedUrl"
13
+ :class="getClasses"
14
+ :style="customStyle"
15
+ :alt="isProfile ? 'Profile image' : 'Uploaded image'"
16
+ @error="onImageError"
17
+ />
18
+ </button>
19
+ <div v-if="uploading" :class="getSkeletonClass" role="status" aria-label="Uploading image" />
20
+ <avatar-cropper
21
+ v-model="showCropper"
22
+ :upload-url="`${uploadServer}${uploadImageName}`"
23
+ :cropper-options="cropperOptions"
24
+ @uploading="handleUploading"
25
+ @uploaded="handleUploaded"
26
+ @completed="handleCompleted"
27
+ @error="handlerError"
28
+ />
29
+ </section>
30
+ </template>
31
+
32
+ <script>
33
+ import AvatarCropper from 'vue-avatar-cropper';
34
+ import SelectAnProfile from '../../../../assets/select-profile.png';
35
+ import SelectAnImage from '../../../../assets/select-tournament.png';
36
+ import loading from '../../../../assets/loading-spinner.gif';
37
+
38
+ function getImageErrorStatus(error, xhr) {
39
+ return error?.context?.response?.status ?? xhr?.status;
40
+ }
41
+
42
+ export default {
43
+ name: 'GenericImageCropper',
44
+ emits: ['update:url', 'update:uploading', 'error:load', 'error:upload'],
45
+ props: {
46
+ urlToImage: {
47
+ type: String,
48
+ default: SelectAnImage
49
+ },
50
+ customClass: {
51
+ type: String,
52
+ default: ''
53
+ },
54
+ customSkeletonClass: {
55
+ type: String,
56
+ default: ''
57
+ },
58
+ customStyle: {
59
+ type: Object,
60
+ default: () => ({})
61
+ },
62
+ uploadImageName: {
63
+ type: String,
64
+ default: 'default-image'
65
+ },
66
+ uploadServer: {
67
+ type: String,
68
+ default: ''
69
+ },
70
+ imageServer: {
71
+ type: String,
72
+ default: ''
73
+ },
74
+ isProfile: {
75
+ type: Boolean,
76
+ default: false
77
+ },
78
+ disabled: {
79
+ type: Boolean,
80
+ default: false
81
+ },
82
+ cropperOptions: {
83
+ type: Object,
84
+ default: () => ({
85
+ aspectRatio: 3 / 2,
86
+ autoCropArea: 1,
87
+ viewMode: 1,
88
+ movable: true,
89
+ zoomable: true
90
+ })
91
+ }
92
+ },
93
+ components: {
94
+ AvatarCropper
95
+ },
96
+ data() {
97
+ return {
98
+ loading,
99
+ showCropper: false,
100
+ uploading: false,
101
+ localImageUrl: this.urlToImage,
102
+ imageLoadFailed: false,
103
+ previewVersion: 0,
104
+ message: ''
105
+ };
106
+ },
107
+ computed: {
108
+ displayedUrl() {
109
+ const fallback = this.isProfile ? SelectAnProfile : SelectAnImage;
110
+ if (this.imageLoadFailed || !this.localImageUrl) return fallback;
111
+ if (!this.previewVersion) return this.localImageUrl;
112
+ const preview = new URL(this.localImageUrl, document.baseURI);
113
+ preview.searchParams.set('preview', this.previewVersion);
114
+ return preview.href;
115
+ },
116
+ getClasses() {
117
+ return this.customClass
118
+ ? this.customClass
119
+ : 'h-52 w-80 border-2 border-dashed rounded-lg bg-contain bg-contain bg-center bg-no-repeat';
120
+ },
121
+ getSkeletonClass() {
122
+ return this.customSkeletonClass
123
+ ? this.customSkeletonClass
124
+ : 'border-2 h-52 w-80 border-dashed rounded-lg bg-quaternaryHighlight animate-pulse';
125
+ }
126
+ },
127
+ watch: {
128
+ urlToImage(url) {
129
+ if (url === this.localImageUrl) return;
130
+ this.localImageUrl = url;
131
+ this.imageLoadFailed = false;
132
+ this.previewVersion = 0;
133
+ }
134
+ },
135
+ methods: {
136
+ setShowCropper() {
137
+ if (this.disabled || this.uploading) return;
138
+ this.showCropper = true;
139
+ },
140
+ setUploading(uploading) {
141
+ this.uploading = uploading;
142
+ this.$emit('update:uploading', uploading);
143
+ },
144
+ handleUploading(event) {
145
+ this.setUploading(true);
146
+ // The cropper exposes the request promise but does not emit rejected fetches.
147
+ event?.response?.catch?.(error => {
148
+ this.handlerError({ type: 'upload', message: error?.message || 'Image upload failed.' });
149
+ });
150
+ },
151
+ handleUploaded(response) {
152
+ const status = response?.response?.status;
153
+ if (!(status >= 200 && status < 300)) {
154
+ this.handlerError({ message: 'Image upload failed.', context: { response: response?.response } });
155
+ return;
156
+ }
157
+ const url = `${this.imageServer}${this.uploadImageName}.png`;
158
+ if (!this.isValidImageUrl(url)) {
159
+ this.handlerError({ message: 'The upload did not provide a valid image URL.' });
160
+ return;
161
+ }
162
+ this.localImageUrl = url;
163
+ this.imageLoadFailed = false;
164
+ this.previewVersion = Date.now();
165
+ this.$emit('update:url', url);
166
+ this.setUploading(false);
167
+ },
168
+ handleCompleted() {
169
+ this.message = 'Upload completed.';
170
+ },
171
+ handlerError(message, type, xhr) {
172
+ this.setUploading(false);
173
+ this.message = typeof message === 'string' ? message : message?.message || 'Image upload failed.';
174
+ const eventName = (message?.type ?? type) === 'load' ? 'error:load' : 'error:upload';
175
+ this.$emit(eventName, { message: this.message, status: getImageErrorStatus(message, xhr) });
176
+ },
177
+ isValidImageUrl(url) {
178
+ if (typeof url !== 'string' || !url.trim()) return false;
179
+ try {
180
+ return ['http:', 'https:'].includes(new URL(url, document.baseURI).protocol);
181
+ } catch {
182
+ return false;
183
+ }
184
+ },
185
+ onImageError() {
186
+ if (this.imageLoadFailed) return;
187
+ this.imageLoadFailed = true;
188
+ this.$emit('error:load', { message: 'Could not load the image.', url: this.localImageUrl });
189
+ }
190
+ }
191
+ };
192
+ </script>
@@ -1,41 +1,48 @@
1
- import BasicEventInfo from './BasicEventInfo.vue';
2
- import singleEventMock from '../../../../../mocks/singleEventMock.js';
3
- import getAllWeapons from '../../../../../mocks/getAllWeapons.js';
4
-
5
- export default {
6
- title: 'Organisms/Wizards/EditEventWizard/BasicEventInfo/BasicEventInfo',
7
- component: BasicEventInfo,
8
- args: {
9
- event: singleEventMock,
10
- currentStep: Number,
11
- steps: [
12
- { name: 'Basic Info', icon: 'fa-circle-info' },
13
- { name: 'Customization', icon: 'fa-star' },
14
- { name: 'Pool Setup', icon: 'fa-table-columns' },
15
- { name: 'DE Promotion', icon: 'fa-list' },
16
- { name: 'Direct Elimination', icon: 'fa-diagram-sankey' }
17
- ],
18
- weapons: getAllWeapons
19
- },
20
- argTypes: {
21
- event: { control: 'object' },
22
- seedWithOptions: { control: 'Array' },
23
- validation: { control: 'object' },
24
- weapons: { control: 'object' }
25
- }
26
- };
27
-
28
- export const Default = {
29
- args: {
30
- event: singleEventMock,
31
- weapons: getAllWeapons,
32
- currentStep: 2,
33
- steps: [
34
- { name: 'Basic Info', icon: 'fa-circle-info' },
35
- { name: 'Customization', icon: 'fa-star' },
36
- { name: 'Pool Setup', icon: 'fa-table-columns' },
37
- { name: 'DE Promotion', icon: 'fa-list' },
38
- { name: 'Direct Elimination', icon: 'fa-diagram-sankey' }
39
- ]
40
- }
41
- };
1
+ import BasicEventInfo from './BasicEventInfo.vue';
2
+ import singleEventMock from '../../../../../mocks/singleEventMock.js';
3
+ import getAllWeapons from '../../../../../mocks/getAllWeapons.js';
4
+
5
+ const eventConfig = { ...singleEventMock, EventPrice: 25.5 };
6
+ const validation = {
7
+ EventName: { invalid: false, message: '' },
8
+ EventPrice: { invalid: false, message: '' }
9
+ };
10
+ const steps = [
11
+ { name: 'Basic Info', icon: 'fa-circle-info' },
12
+ { name: 'Customization', icon: 'fa-star' },
13
+ { name: 'Pool Setup', icon: 'fa-table-columns' },
14
+ { name: 'DE Promotion', icon: 'fa-list' },
15
+ { name: 'Direct Elimination', icon: 'fa-diagram-sankey' }
16
+ ];
17
+
18
+ export default {
19
+ title: 'Organisms/Wizards/EditEventWizard/BasicEventInfo/BasicEventInfo',
20
+ component: BasicEventInfo,
21
+ args: { eventConfig, validation, currentStep: 0, steps, weapons: getAllWeapons },
22
+ argTypes: {
23
+ eventConfig: { control: 'object' },
24
+ validation: { control: 'object' },
25
+ weapons: { control: 'object' },
26
+ steps: { control: 'object' },
27
+ currentStep: { control: 'number' }
28
+ }
29
+ };
30
+
31
+ export const Default = {
32
+ args: { eventConfig, validation, currentStep: 0, steps, weapons: getAllWeapons }
33
+ };
34
+
35
+ export const FreeEvent = {
36
+ args: { ...Default.args, eventConfig: { ...eventConfig, EventPrice: 0 } }
37
+ };
38
+
39
+ export const InvalidPrice = {
40
+ args: {
41
+ ...Default.args,
42
+ eventConfig: { ...eventConfig, EventPrice: -5 },
43
+ validation: {
44
+ ...validation,
45
+ EventPrice: { invalid: true, message: 'Price must be a non-negative number.' }
46
+ }
47
+ }
48
+ };