l-min-components 1.0.1025 → 1.0.1029

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "l-min-components",
3
- "version": "1.0.1025",
3
+ "version": "1.0.1029",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -44,21 +44,26 @@ const InstructorAccountSwitcher = ({
44
44
  const [dropdown, setDropdown] = useState(false);
45
45
 
46
46
  const getCookie = () => {
47
- let cookieValue = null;
48
- const cookieName = "affiliateAccount";
47
+ const cookies = document.cookie;
48
+ const cookieArray = cookies.split(";");
49
49
 
50
- const cookies = document.cookie.split(";");
51
- for (let i = 0; i < cookies.length; i++) {
52
- const cookie = cookies[i].trim();
53
- if (cookie.startsWith(cookieName + "=")) {
54
- cookieValue = cookie.substring(cookieName.length + 1);
55
- break;
50
+ let affiliateAccount = null;
51
+
52
+ cookieArray?.forEach((cookieValue) => {
53
+ const cookie = cookieValue?.trim();
54
+ if (cookie.startsWith("affiliateAccount=")) {
55
+ affiliateAccount = cookie.substring(
56
+ "affiliateAccount=".length,
57
+ cookie.length
58
+ );
56
59
  }
57
- }
60
+ });
58
61
 
59
- return cookieValue;
62
+ return affiliateAccount;
60
63
  };
61
64
 
65
+ const cookieValue = getCookie();
66
+
62
67
  const setCookie = (id) => {
63
68
  const date = new Date();
64
69
  date.setDate(date.getDate() + 20);
@@ -73,53 +78,40 @@ const InstructorAccountSwitcher = ({
73
78
 
74
79
  const handleSwitch = (value) => {
75
80
  if (value === 2) {
76
- setSwitchValue("affiliates");
77
81
  if (selectedValue) {
78
82
  setCookie(selectedValue?.id);
79
83
  }
80
84
  } else {
81
- setSwitchValue(false);
82
- let cookieValue = getCookie();
83
- if (cookieValue) deleteCookies("affiliateAccount");
85
+ if (cookieValue) {
86
+ deleteCookies("affiliateAccount");
87
+ }
84
88
  }
85
89
  window.location.href = "/instructor/dashboard";
86
90
  };
87
91
 
88
92
  useEffect(() => {
89
- let cookieValue = getCookie();
90
93
  if (cookieValue) {
91
94
  setSwitchValue("affiliates");
95
+ onChange({ id: selectedValue?.id });
92
96
  } else {
93
97
  setSwitchValue(null);
98
+ onChange(null);
94
99
  }
95
100
  }, []);
96
101
 
97
102
  useEffect(() => {
98
- handleGetDefaultAffiliate()
99
- .then((res) => {
100
- if (res?.data) {
101
- const value = res?.data;
102
- const image = value?.profile_photo?.url;
103
- setSelectedValue(() => ({
104
- name: value?.display_name,
105
- image,
106
- id: value?.id,
107
- }));
108
- }
109
- })
110
- .catch(() => {
111
- deleteCookies("affiliateAccount");
112
- });
113
- }, [setDefaultAffiliateData?.data, switchValue]);
114
-
115
- useEffect(() => {
116
- const value = JSON.parse(localStorage.getItem("affiliates"));
117
- if (value) {
118
- setAccountType && setAccountType(switchValue);
119
- } else {
120
- setAccountType && setAccountType(switchValue);
121
- }
122
- }, [switchValue]);
103
+ handleGetDefaultAffiliate().then((res) => {
104
+ if (res?.data) {
105
+ const value = res?.data;
106
+ const image = value?.profile_photo?.url;
107
+ setSelectedValue(() => ({
108
+ name: value?.display_name,
109
+ image,
110
+ id: value?.id,
111
+ }));
112
+ }
113
+ });
114
+ }, []);
123
115
 
124
116
  const handleSelection = async (item) => {
125
117
  const res = await handleSetDefaultAffiliate({
@@ -127,19 +119,10 @@ const InstructorAccountSwitcher = ({
127
119
  });
128
120
  if (res?.data) {
129
121
  setCookie(item?.id);
130
- setSelectedValue(item);
131
- setDropdown(false);
132
122
  window.location.href = "/instructor/dashboard";
133
123
  }
134
124
  };
135
125
 
136
- useEffect(() => {
137
- if (onChange) {
138
- let cookieValue = getCookie();
139
- if (cookieValue) onChange({ id: selectedValue?.id });
140
- else onChange(null);
141
- }
142
- }, [selectedValue]);
143
126
  return getAllAffiliateData?.data?.count && !search ? (
144
127
  <>
145
128
  {(setDefaultAffiliateData?.loading ||