Skip to content

Commit

Permalink
Request access
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Jun 20, 2024
1 parent 3a16a14 commit e46463f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions apps/dashboard/src/actions/request-access-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"use server";

import { getUser } from "@midday/supabase/cached-queries";
import { PlainClient } from "@team-plain/typescript-sdk";
import { action } from "./safe-action";
import { requestAccessSchema } from "./schema";

const client = new PlainClient({
apiKey: process.env.PLAIN_API_KEY!,
});

export const requestAccessAction = action(requestAccessSchema, async () => {
const user = await getUser();

const customer = await client.upsertCustomer({
identifier: {
emailAddress: user.data.email,
},
onCreate: {
fullName: user.data.full_name,
externalId: user.data.id,
email: {
email: user.data.email,
isVerified: true,
},
},
onUpdate: {},
});

const response = await client.createThread({
title: "Invoice access",
customerIdentifier: {
customerId: customer.data?.customer.id,
},
// Support
labelTypeIds: ["lt_01HV93FQT6NSC1EN2HHA6BG9WK"],
components: [
{
componentText: {
text: "Invoice access",
},
},
],
});

return response;
});

0 comments on commit e46463f

Please sign in to comment.