-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tags to customers * Add tags to customers
- Loading branch information
Showing
19 changed files
with
322 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
apps/dashboard/src/actions/customer/create-customer-tag-action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use server"; | ||
|
||
import { LogEvents } from "@midday/events/events"; | ||
import { revalidateTag } from "next/cache"; | ||
import { authActionClient } from "../safe-action"; | ||
import { createCustomerTagSchema } from "./schema"; | ||
|
||
export const createCustomerTagAction = authActionClient | ||
.schema(createCustomerTagSchema) | ||
.metadata({ | ||
name: "create-customer-tag", | ||
track: { | ||
event: LogEvents.CreateCustomerTag.name, | ||
channel: LogEvents.CreateCustomerTag.channel, | ||
}, | ||
}) | ||
.action( | ||
async ({ parsedInput: { tagId, customerId }, ctx: { user, supabase } }) => { | ||
const { data } = await supabase.from("customer_tags").insert({ | ||
tag_id: tagId, | ||
customer_id: customerId, | ||
team_id: user.team_id!, | ||
}); | ||
|
||
revalidateTag(`customers_${user.team_id}`); | ||
|
||
return data; | ||
}, | ||
); |
29 changes: 29 additions & 0 deletions
29
apps/dashboard/src/actions/customer/delete-customer-tag-action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use server"; | ||
|
||
import { LogEvents } from "@midday/events/events"; | ||
import { revalidateTag } from "next/cache"; | ||
import { authActionClient } from "../safe-action"; | ||
import { deleteCustomerTagSchema } from "./schema"; | ||
|
||
export const deleteCustomerTagAction = authActionClient | ||
.schema(deleteCustomerTagSchema) | ||
.metadata({ | ||
name: "delete-customer-tag", | ||
track: { | ||
event: LogEvents.DeleteCustomerTag.name, | ||
channel: LogEvents.DeleteCustomerTag.channel, | ||
}, | ||
}) | ||
.action( | ||
async ({ parsedInput: { tagId, customerId }, ctx: { user, supabase } }) => { | ||
const { data } = await supabase | ||
.from("customer_tags") | ||
.delete() | ||
.eq("customer_id", customerId) | ||
.eq("tag_id", tagId); | ||
|
||
revalidateTag(`customers_${user.team_id}`); | ||
|
||
return data; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { z } from "zod"; | ||
|
||
export const deleteCustomerTagSchema = z.object({ | ||
tagId: z.string(), | ||
customerId: z.string(), | ||
}); | ||
|
||
export const createCustomerTagSchema = z.object({ | ||
tagId: z.string(), | ||
customerId: z.string(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.