6dc556b704
* Updated “Twitter” to be “X (Twitter)” * added Textarea to storybook * Updated textarea styling to match input field * WIP adding new text field to org creation page * Added description to field * Submit feedback to Plain when an org signs up * Formatting improvement * type improvement * removed userId * Moved submitting to Plain into its own file * Change orgName with name * use sendToPlain function for the help & feedback email form * use name not orgName * import cleanup * Downgrading plan form uses sendToPlain * Get the userId from requireUser only * Added whitespace-pre-wrap to the message property on the run page * use requireUserId * Removed old Plain submit code
60 lines
1.3 KiB
TypeScript
60 lines
1.3 KiB
TypeScript
import { PlainClient, uiComponent } from "@team-plain/typescript-sdk";
|
|
import { env } from "~/env.server";
|
|
|
|
type Input = {
|
|
userId: string;
|
|
email: string;
|
|
name: string;
|
|
title: string;
|
|
components: ReturnType<typeof uiComponent.text>[];
|
|
};
|
|
|
|
export async function sendToPlain({ userId, email, name, title, components }: Input) {
|
|
if (!env.PLAIN_API_KEY) {
|
|
return;
|
|
}
|
|
|
|
const client = new PlainClient({
|
|
apiKey: env.PLAIN_API_KEY,
|
|
});
|
|
|
|
const upsertCustomerRes = await client.upsertCustomer({
|
|
identifier: {
|
|
emailAddress: email,
|
|
},
|
|
onCreate: {
|
|
externalId: userId,
|
|
fullName: name,
|
|
email: {
|
|
email: email,
|
|
isVerified: true,
|
|
},
|
|
},
|
|
onUpdate: {
|
|
externalId: { value: userId },
|
|
fullName: { value: name },
|
|
email: {
|
|
email: email,
|
|
isVerified: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
if (upsertCustomerRes.error) {
|
|
console.error("Failed to upsert customer in Plain", upsertCustomerRes.error);
|
|
return;
|
|
}
|
|
|
|
const createThreadRes = await client.createThread({
|
|
customerIdentifier: {
|
|
customerId: upsertCustomerRes.data.customer.id,
|
|
},
|
|
title: title,
|
|
components: components,
|
|
});
|
|
|
|
if (createThreadRes.error) {
|
|
console.error("Failed to create thread in Plain", createThreadRes.error);
|
|
}
|
|
}
|