@stokr/components-library 3.0.45 → 3.0.47

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.
@@ -29,6 +29,7 @@ const defaultProject = {
29
29
  const NewVentureModal = (props) => {
30
30
  const navigate = useNavigate();
31
31
  const { user } = useContext(AuthContext);
32
+ const isLoggedIn = !!user?._id;
32
33
  const {
33
34
  title = "Register Your Interest",
34
35
  description = "Register your interest and learn more about this investment opportunity.",
@@ -66,7 +67,10 @@ const NewVentureModal = (props) => {
66
67
  salesChannel,
67
68
  customSuccessMessage
68
69
  });
69
- const validationSchema = Yup.object().shape({
70
+ const validationSchema = isLoggedIn ? Yup.object().shape({
71
+ email: Yup.string().nullable(),
72
+ name: Yup.string().nullable()
73
+ }) : Yup.object().shape({
70
74
  email: Yup.string().matches(emailRegex, "Oops, that's not a valid address").required("Oops, this can't be blank"),
71
75
  name: Yup.string().required("Oops, this can't be blank")
72
76
  });
@@ -112,6 +116,7 @@ const NewVentureModal = (props) => {
112
116
  ] }) : /* @__PURE__ */ jsx(
113
117
  Formik,
114
118
  {
119
+ enableReinitialize: true,
115
120
  initialValues: {
116
121
  email: email || "",
117
122
  name: name || "",
@@ -133,20 +138,6 @@ const NewVentureModal = (props) => {
133
138
  };
134
139
  const oneOfCheckbox = values.mailingList && !mailingListDisabled || values.privateInvestorList && !privateInvestorListDisabled;
135
140
  const optionalCheckBoxForm = optionalCheckBox ? values.optionalCheckBoxChecked : true;
136
- if (email && !values.email) {
137
- setFieldValue("email", email);
138
- setFieldTouched("email");
139
- }
140
- if (name && !values.name) {
141
- setFieldValue("name", name);
142
- setFieldTouched("name");
143
- }
144
- if (mailingList && !values.mailingList) {
145
- setFieldValue("mailingList", mailingList);
146
- }
147
- if (privateInvestorList && !values.privateInvestorList) {
148
- setFieldValue("privateInvestorList", privateInvestorList);
149
- }
150
141
  const handleCheckboxChange = (e) => {
151
142
  handleChange(e);
152
143
  if (e.target.checked) {
@@ -155,10 +146,11 @@ const NewVentureModal = (props) => {
155
146
  updateCheckedCheckboxes(checkedCheckboxes.filter((item) => item !== e.target.id));
156
147
  }
157
148
  };
158
- var submitDisabled = !touched.email || !!errors.email || !touched.name || !!errors.name || isSubmitting || !oneOfCheckbox || !optionalCheckBoxForm;
149
+ const requiresIdentityFields = !isLoggedIn;
150
+ const submitDisabled = requiresIdentityFields && (!values.email || !!errors.email || !values.name || !!errors.name) || isSubmitting || !oneOfCheckbox || !optionalCheckBoxForm;
159
151
  return /* @__PURE__ */ jsxs(stdin_default, { children: [
160
152
  /* @__PURE__ */ jsx(ComponentWrapper, { noPadding: true, children: /* @__PURE__ */ jsxs(FormField, { children: [
161
- !user?._id && /* @__PURE__ */ jsxs(Fragment, { children: [
153
+ !isLoggedIn && /* @__PURE__ */ jsxs(Fragment, { children: [
162
154
  /* @__PURE__ */ jsx(
163
155
  Input,
164
156
  {
@@ -1,5 +1,5 @@
1
1
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
- import { useState, useContext, useEffect, useCallback } from "react";
2
+ import { useState, useContext, useCallback, useEffect } from "react";
3
3
  import { AuthContext } from "../context/AuthContext.js";
4
4
  import fetchDataPublic from "../api/fetchDataPublic.js";
5
5
  import parse from "html-react-parser";
@@ -75,52 +75,25 @@ const updateUserSubscription = (user, project, updates) => {
75
75
  }
76
76
  return { ...user, ...updates };
77
77
  };
78
+ const resolveUserDisplayName = (user) => {
79
+ if (!user) return "";
80
+ const fullNameFromParts = `${user.firstName || ""} ${user.lastName || ""}`.trim();
81
+ return user.username || user.name || user.fullName || fullNameFromParts || "";
82
+ };
78
83
  const useNewVentureForm = ({ project, user, salesChannel, customSuccessMessage }) => {
79
84
  const [formValues, setFormValues] = useState(initialState);
80
85
  const { setUser, checkPrivateInvestorAll, checkIfUserSubscribedAll } = useContext(AuthContext);
81
86
  const { checkboxes, isLoading: isLoadingCheckboxes } = useCheckboxes("newVentureModal", {
82
87
  group: "newVentureModal"
83
88
  });
84
- useEffect(() => {
85
- let formValuesCopy = { ...formValues };
86
- if (checkboxes) {
87
- Object.values(checkboxes).forEach((checkbox) => {
88
- if (checkbox.label === "createPrivateInvestor" && !formValuesCopy.privateInvestorListDisabled) {
89
- formValuesCopy.privateInvestorListText = parse(checkbox.agreementText);
90
- } else if (checkbox.label === "subscribeToProject" && !formValuesCopy.mailingListDisabled) {
91
- formValuesCopy.mailingListText = parse(checkbox.agreementText);
92
- }
93
- });
94
- }
95
- if (user?._id) {
96
- formValuesCopy.email = user.email;
97
- formValuesCopy.name = user.username;
98
- const projectSubscription = getProjectSubscription(user, project);
99
- if (projectSubscription.isPrivateInvestor) {
100
- formValuesCopy.privateInvestorListText = "You are already registered on the whitelist.";
101
- formValuesCopy.privateInvestorList = true;
102
- formValuesCopy.privateInvestorListDisabled = true;
103
- } else if (projectSubscription.privateInvestorStatus && projectSubscription.privateInvestorStatus !== "Admitted") {
104
- formValuesCopy.privateInvestorListText = "Your profile is under review. An account manager will reach out to you to confirm your eligibility.";
105
- formValuesCopy.privateInvestorList = true;
106
- formValuesCopy.privateInvestorListDisabled = true;
107
- }
108
- if (projectSubscription.isSubscribed) {
109
- formValuesCopy.mailingList = true;
110
- formValuesCopy.mailingListText = "You already subscribed to the email notification list.";
111
- formValuesCopy.mailingListDisabled = true;
112
- }
113
- }
114
- setFormValues(formValuesCopy);
115
- }, [user, checkboxes, project, formValues]);
116
89
  const handleSubmit = useCallback(
117
90
  async (values) => {
118
91
  setFormValues((prev) => ({ ...prev, isSubmitting: true }));
119
92
  try {
120
93
  const dataToSend = {
121
- email: values.email,
94
+ email: values.email || user?.email || "",
122
95
  projectId: project._id,
123
- name: values.name,
96
+ name: values.name || resolveUserDisplayName(user),
124
97
  checkedCheckboxes: formValues.checkedCheckboxes,
125
98
  salesChannel: salesChannel ? salesChannel : window.location.pathname.includes("featured-assets") ? "featuredAssets" : "investor"
126
99
  };
@@ -224,8 +197,8 @@ const useNewVentureForm = ({ project, user, salesChannel, customSuccessMessage }
224
197
  });
225
198
  }
226
199
  if (user?._id) {
227
- formValuesCopy.email = user.email;
228
- formValuesCopy.name = user.username;
200
+ formValuesCopy.email = user.email || "";
201
+ formValuesCopy.name = resolveUserDisplayName(user);
229
202
  const projectSubscription = getProjectSubscription(user, project);
230
203
  if (projectSubscription.isPrivateInvestor) {
231
204
  formValuesCopy.privateInvestorListText = "You are already registered on the whitelist.";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stokr/components-library",
3
- "version": "3.0.45",
3
+ "version": "3.0.47",
4
4
  "description": "STOKR - Components Library",
5
5
  "author": "Bilal Hodzic <bilal@stokr.io>",
6
6
  "license": "MIT",