@stokr/components-library 3.0.46 → 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
|
-
|
|
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
|
-
!
|
|
153
|
+
!isLoggedIn && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
162
154
|
/* @__PURE__ */ jsx(
|
|
163
155
|
Input,
|
|
164
156
|
{
|
|
@@ -75,6 +75,11 @@ 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);
|
|
@@ -86,9 +91,9 @@ const useNewVentureForm = ({ project, user, salesChannel, customSuccessMessage }
|
|
|
86
91
|
setFormValues((prev) => ({ ...prev, isSubmitting: true }));
|
|
87
92
|
try {
|
|
88
93
|
const dataToSend = {
|
|
89
|
-
email: values.email,
|
|
94
|
+
email: values.email || user?.email || "",
|
|
90
95
|
projectId: project._id,
|
|
91
|
-
name: values.name,
|
|
96
|
+
name: values.name || resolveUserDisplayName(user),
|
|
92
97
|
checkedCheckboxes: formValues.checkedCheckboxes,
|
|
93
98
|
salesChannel: salesChannel ? salesChannel : window.location.pathname.includes("featured-assets") ? "featuredAssets" : "investor"
|
|
94
99
|
};
|
|
@@ -192,8 +197,8 @@ const useNewVentureForm = ({ project, user, salesChannel, customSuccessMessage }
|
|
|
192
197
|
});
|
|
193
198
|
}
|
|
194
199
|
if (user?._id) {
|
|
195
|
-
formValuesCopy.email = user.email;
|
|
196
|
-
formValuesCopy.name = user
|
|
200
|
+
formValuesCopy.email = user.email || "";
|
|
201
|
+
formValuesCopy.name = resolveUserDisplayName(user);
|
|
197
202
|
const projectSubscription = getProjectSubscription(user, project);
|
|
198
203
|
if (projectSubscription.isPrivateInvestor) {
|
|
199
204
|
formValuesCopy.privateInvestorListText = "You are already registered on the whitelist.";
|