-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: mathieu <mathieu.dreano@gmail.com>
- Loading branch information
1 parent
f0d5cde
commit 0bf21d1
Showing
14 changed files
with
298 additions
and
105 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/bruno-app/src/components/Environments/EnvironmentSelector/StyledWrapper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ronments/EnvironmentSettings/EnvironmentList/EnvironmentDetails/EnvironmentColor/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React from 'react'; | ||
import { useRef, useEffect } from 'react'; | ||
import toast from 'react-hot-toast'; | ||
import { useTheme } from 'providers/Theme'; | ||
import { useDispatch } from 'react-redux'; | ||
import { saveEnvironmentColor } from 'providers/ReduxStore/slices/collections/actions'; | ||
import { useFormik } from 'formik'; | ||
import * as Yup from 'yup'; | ||
import { CirclePicker } from 'react-color'; | ||
import { selectEnvironment as _selectEnvironment } from 'providers/ReduxStore/slices/collections'; | ||
|
||
const EnvironmentColor = ({ environment, onColorChange, collectionUid }) => { | ||
const dispatch = useDispatch(); | ||
|
||
const formik = useFormik({ | ||
enableReinitialize: true, | ||
initialValues: { | ||
color: environment.color || '' | ||
}, | ||
validationSchema: Yup.object({ | ||
color: Yup.string().optional() | ||
}), | ||
onSubmit: (values) => { | ||
if (!formik.dirty) { | ||
toast.error('Nothing to save'); | ||
return; | ||
} | ||
dispatch(saveEnvironmentColor(values.color, environment.uid, collectionUid)) | ||
.then(() => { | ||
toast.success('Environment color changed successfully'); | ||
onColorChange(values.color); | ||
}) | ||
.catch((e) => { | ||
console.log(e); | ||
toast.error('An error occurred while changing the environment color'); | ||
}); | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
if (formik.dirty) { | ||
formik.handleSubmit(); | ||
} | ||
}, [formik.values.color]); | ||
|
||
return ( | ||
<CirclePicker | ||
id="environment-color" | ||
circleSize={12} | ||
circleSpacing={5} | ||
colors={[ | ||
'#9c27b0', | ||
'#3f51b5', | ||
'#03a9f4', | ||
'#009688', | ||
'#8bc34a', | ||
'#ffeb3b', | ||
'#ff9800', | ||
'#ff5722', | ||
'#795548', | ||
'#607d8b' | ||
]} | ||
color={environment.color} | ||
onChangeComplete={(color) => formik.setFieldValue('color', color.hex)} | ||
value={formik.values.color || ''} | ||
/> | ||
); | ||
}; | ||
export default EnvironmentColor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.