-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Save company size to loops #796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } from "@/utils/actions/onboarding.validation"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { actionClientUser } from "@/utils/actions/safe-action"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import prisma from "@/utils/prisma"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { updateContactCompanySize } from "@inboxzero/loops"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const completedOnboardingAction = actionClientUser | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .metadata({ name: "completedOnboarding" }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -22,7 +23,7 @@ export const saveOnboardingAnswersAction = actionClientUser | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .action( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parsedInput: { surveyId, questions, answers }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx: { userId }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ctx: { userId, logger }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Helper function to extract survey answers from the response format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function extractSurveyAnswers(questions: any[], answers: any) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -105,10 +106,9 @@ export const saveOnboardingAnswersAction = actionClientUser | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Extract individual survey answers for easier querying | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const extractedAnswers = extractSurveyAnswers(questions, answers); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await prisma.user.update({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const userPromise = prisma.user.update({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| where: { id: userId }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onboardingAnswers: { surveyId, questions, answers }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -120,6 +120,20 @@ export const saveOnboardingAnswersAction = actionClientUser | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| surveyImprovements: extractedAnswers.surveyImprovements, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await Promise.all([ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userPromise, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (extractedAnswers.surveyCompanySize) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateContactCompanySize( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| userId, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updateContactCompanySize expects an email address, but userId is passed here. Use the user’s email (e.g., from the updated user record) to ensure the correct contact is updated. Prompt for AI agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extractedAnswers.surveyCompanySize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ).catch((error) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.error("Error updating company size", { error }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+124
to
+136
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Company size update never runs (async fn not invoked) and wrong identifier used.
Apply these changes: - await Promise.all([
- userPromise,
- async () => {
- if (extractedAnswers.surveyCompanySize) {
- updateContactCompanySize(
- userId,
- extractedAnswers.surveyCompanySize,
- ).catch((error) => {
- logger.error("Error updating company size", { error });
- });
- }
- },
- ]);
+ await Promise.all([
+ userPromise,
+ (async () => {
+ const size = extractedAnswers.surveyCompanySize;
+ if (typeof size !== "number" || !Number.isFinite(size)) return;
+ const { email } = await userPromise; // from select below
+ if (!email) return;
+ try {
+ const resp = await updateContactCompanySize(email, size);
+ if (!resp.success) {
+ logger.error("Loops updateContactCompanySize returned success=false", { userId, email, companySize: size });
+ }
+ } catch (error) {
+ logger.error("Error updating company size", { error, userId, email, companySize: size });
+ }
+ })(),
+ ]);Additionally, if any UI depends on these fields, consider 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v2.9.42 | ||
| v2.9.43 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The async function is being passed to Promise.all without being invoked, so the update logic never runs. Pass a promise to Promise.all by immediately invoking the async arrow or by creating a promise and including that instead.
Prompt for AI agents