18
18
19
19
import {
20
20
AppstoreAddOutlined ,
21
+ CopyOutlined ,
21
22
DeleteOutlined ,
22
23
LoadingOutlined ,
23
24
QrcodeOutlined ,
@@ -39,7 +40,6 @@ import {
39
40
Row ,
40
41
Space ,
41
42
Spin ,
42
- Tooltip ,
43
43
Typography ,
44
44
} from 'antd' ;
45
45
import { QRCodeSVG } from 'qrcode.react' ;
@@ -59,11 +59,12 @@ import {useColors} from '~/src/hooks/useColors';
59
59
import { useStandardColorSets } from '~/src/hooks/useStandardColorSets' ;
60
60
import { hasAccessTo } from '~/src/services/auth/utils' ;
61
61
import { MAX_COLORS_IN_MIXTURE } from '~/src/services/color/color-mixer' ;
62
- import { COLOR_TYPES } from '~/src/services/color/colors' ;
62
+ import { COLOR_TYPES , compareByDate } from '~/src/services/color/colors' ;
63
63
import type { ColorBrandDefinition , ColorSetDefinition , ColorType } from '~/src/services/color/types' ;
64
64
import { colorSetToUrl } from '~/src/services/url/url-parser' ;
65
65
import { useAppStore } from '~/src/stores/app-store' ;
66
66
import { TabKey } from '~/src/tabs' ;
67
+ import { reverseOrder } from '~/src/utils/array' ;
67
68
68
69
import { ColorBrandSelect } from './color-set/ColorBrandSelect' ;
69
70
import { ColorSelect } from './color-set/ColorSelect' ;
@@ -226,15 +227,17 @@ export const ColorSetChooser = forwardRef<ChangableComponent, Props>(function Co
226
227
} ) ;
227
228
if ( confirmed ) {
228
229
const { id, ...colorSet } = form . getFieldsValue ( ) ;
229
- await saveColorSet (
230
- user ,
231
- {
232
- ...colorSet ,
233
- ...( id ? { id} : { } ) ,
234
- } ,
235
- brands ,
236
- colors ,
237
- false
230
+ form . setFieldsValue (
231
+ await saveColorSet (
232
+ user ,
233
+ {
234
+ ...colorSet ,
235
+ ...( id ? { id} : { } ) ,
236
+ } ,
237
+ brands ,
238
+ colors ,
239
+ false
240
+ )
238
241
) ;
239
242
}
240
243
setHasUnsavedChanges ( false ) ;
@@ -349,6 +352,7 @@ export const ColorSetChooser = forwardRef<ChangableComponent, Props>(function Co
349
352
} ;
350
353
351
354
const handleSubmit = async ( values : ColorSetDefinition ) => {
355
+ setHasUnsavedChanges ( false ) ;
352
356
const { id, ...colorSet } = values ;
353
357
form . setFieldsValue (
354
358
await saveColorSet (
@@ -361,13 +365,22 @@ export const ColorSetChooser = forwardRef<ChangableComponent, Props>(function Co
361
365
colors
362
366
)
363
367
) ;
364
- setHasUnsavedChanges ( false ) ;
365
368
} ;
366
369
367
370
const handleSubmitFailed = ( ) => {
368
371
void message . error ( 'Fill in the required fields' ) ;
369
372
} ;
370
373
374
+ const handleDuplicateButtonClick = ( ) => {
375
+ const { id : _id , name : _name , ...colorSet } = form . getFieldsValue ( ) ;
376
+ form . setFieldsValue ( {
377
+ id : NEW_COLOR_SET ,
378
+ name : undefined ,
379
+ ...colorSet ,
380
+ } ) ;
381
+ setHasUnsavedChanges ( true ) ;
382
+ } ;
383
+
371
384
const handleDeleteButtonClick = async ( ) => {
372
385
setHasUnsavedChanges ( true ) ;
373
386
if ( selectedColorSetId ) {
@@ -376,7 +389,9 @@ export const ColorSetChooser = forwardRef<ChangableComponent, Props>(function Co
376
389
type : selectedType ,
377
390
} ;
378
391
if ( selectedType ) {
379
- const [ latestColorSetsByType ] = await loadColorSetsByType ( selectedType ) ;
392
+ const [ latestColorSetsByType ] = ( await loadColorSetsByType ( selectedType ) ) . sort (
393
+ reverseOrder ( compareByDate )
394
+ ) ;
380
395
values = latestColorSetsByType ?? values ;
381
396
}
382
397
form . resetFields ( ) ;
@@ -633,16 +648,15 @@ export const ColorSetChooser = forwardRef<ChangableComponent, Props>(function Co
633
648
< Space wrap >
634
649
{ ! isAuthLoading &&
635
650
( isAccessAllowed ? (
636
- < Tooltip title = "Save the changes to the color set" trigger = "focus" >
637
- < Button
638
- ref = { saveButtonRef }
639
- icon = { < SaveOutlined /> }
640
- type = "primary"
641
- htmlType = "submit"
642
- >
643
- Save & proceed
644
- </ Button >
645
- </ Tooltip >
651
+ < Button
652
+ ref = { saveButtonRef }
653
+ icon = { < SaveOutlined /> }
654
+ title = "Save the changes to this color set"
655
+ type = "primary"
656
+ htmlType = "submit"
657
+ >
658
+ Save & proceed
659
+ </ Button >
646
660
) : (
647
661
< >
648
662
< LoginButton />
@@ -659,25 +673,34 @@ export const ColorSetChooser = forwardRef<ChangableComponent, Props>(function Co
659
673
</ Button >
660
674
) }
661
675
{ ! ! selectedColorSetId && (
662
- < Popconfirm
663
- title = "Delete the color set"
664
- description = "Are you sure you want to delete this color set?"
665
- onConfirm = { ( ) => {
666
- void handleDeleteButtonClick ( ) ;
667
- } }
668
- okText = "Yes"
669
- cancelText = "No"
670
- >
676
+ < >
671
677
< Button
672
- icon = { < DeleteOutlined /> }
678
+ icon = { < CopyOutlined /> }
679
+ title = "Create a duplicate of this color set for further modification"
680
+ onClick = { handleDuplicateButtonClick }
681
+ >
682
+ Duplicate
683
+ </ Button >
684
+ < Popconfirm
673
685
title = "Delete the color set"
674
- onClick = { e => {
675
- e . stopPropagation ( ) ;
686
+ description = "Are you sure you want to delete this color set?"
687
+ onConfirm = { ( ) => {
688
+ void handleDeleteButtonClick ( ) ;
676
689
} }
690
+ okText = "Yes"
691
+ cancelText = "No"
677
692
>
678
- Delete
679
- </ Button >
680
- </ Popconfirm >
693
+ < Button
694
+ icon = { < DeleteOutlined /> }
695
+ title = "Delete this color set"
696
+ onClick = { e => {
697
+ e . stopPropagation ( ) ;
698
+ } }
699
+ >
700
+ Delete
701
+ </ Button >
702
+ </ Popconfirm >
703
+ </ >
681
704
) }
682
705
</ Space >
683
706
</ Form . Item >
0 commit comments