@visns-studio/visns-components 3.3.1 → 3.3.2

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.
@@ -41,28 +41,43 @@ const Profile = ({ userProfile, setUserProfile }) => {
41
41
  }));
42
42
  };
43
43
 
44
- const handleSubmitProfile = (e) => {
45
- e.preventDefault();
44
+ const handleSubmitProfile = async (e) => {
45
+ try {
46
+ if (e) {
47
+ e.preventDefault();
48
+ }
46
49
 
47
- if (profile.name.trim() === '' || profile.email.trim() === '') {
48
- setInputClasses({
49
- name: profile.name.trim() === '' ? 'inputError' : '',
50
- email: profile.email.trim() === '' ? 'inputError' : '',
51
- });
50
+ // Validate required fields
51
+ if (profile.name.trim() === '' || profile.email.trim() === '') {
52
+ setInputClasses({
53
+ name: profile.name.trim() === '' ? 'inputError' : '',
54
+ email: profile.email.trim() === '' ? 'inputError' : '',
55
+ });
52
56
 
53
- toast.error('Please fill in all the required fields.');
54
- } else {
55
- CustomFetch(
56
- `/ajax/users/${userProfile.id}`,
57
- 'PUT',
58
- profile,
59
- function (result) {
60
- setUserProfile(result.user);
61
- toast.success(
62
- 'Your profile has been successfully updated.'
63
- );
57
+ toast.error('Please fill in all the required fields.');
58
+ } else {
59
+ // Create a new payload object
60
+ let payload = {
61
+ name: profile.name,
62
+ email: profile.email,
63
+ };
64
+
65
+ // Conditionally add password to payload if it has a value
66
+ if (profile.password.trim() !== '') {
67
+ payload.password = profile.password;
64
68
  }
65
- );
69
+
70
+ const res = await CustomFetch(
71
+ `/ajax/users/${userProfile.id}`,
72
+ 'PUT',
73
+ payload
74
+ );
75
+
76
+ setUserProfile(res.data.user);
77
+ toast.success('Your profile has been successfully updated.');
78
+ }
79
+ } catch (err) {
80
+ console.log(err);
66
81
  }
67
82
  };
68
83
 
package/package.json CHANGED
@@ -49,7 +49,7 @@
49
49
  "react-dom": "^17.0.1"
50
50
  },
51
51
  "name": "@visns-studio/visns-components",
52
- "version": "3.3.1",
52
+ "version": "3.3.2",
53
53
  "description": "Various packages to assist in the development of our Custom Applications.",
54
54
  "main": "index.js",
55
55
  "scripts": {