Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: send feedback to customer-specific slack channel

Brad Barbined6ab2d66f2c
diff --git a/apps/erp/app/modules/api/ui/Snippets.tsx b/apps/erp/app/modules/api/ui/Snippets.tsx
index c6225b9670..9fb1cff402 100644
--- a/apps/erp/app/modules/api/ui/Snippets.tsx
+++ b/apps/erp/app/modules/api/ui/Snippets.tsx
@@ -130,7 +130,7 @@ curl '${endpoint}/rest/v1/' \\
language: "js",
code: `
const SUPABASE_URL = "${endpoint}"
-const supabase = createClient(SUPABASE_URL, process.env.${
+const carbon = createClient(SUPABASE_URL, process.env.${
keyName || "SUPABASE_KEY"
});
`,
@@ -191,7 +191,7 @@ else console.log(data)
js: {
language: "js",
code: `
-const ${listenerName} = supabase.channel('custom-all-channel')
+const ${listenerName} = carbon.channel('custom-all-channel')
.on(
'postgres_changes',
{ event: '*', schema: 'public', table: '${resourceId}' },
@@ -211,7 +211,7 @@ const ${listenerName} = supabase.channel('custom-all-channel')
js: {
language: "js",
code: `
-const ${listenerName} = supabase.channel('custom-insert-channel')
+const ${listenerName} = carbon.channel('custom-insert-channel')
.on(
'postgres_changes',
{ event: 'INSERT', schema: 'public', table: '${resourceId}' },
@@ -231,7 +231,7 @@ const ${listenerName} = supabase.channel('custom-insert-channel')
js: {
language: "js",
code: `
-const ${listenerName} = supabase.channel('custom-update-channel')
+const ${listenerName} = carbon.channel('custom-update-channel')
.on(
'postgres_changes',
{ event: 'UPDATE', schema: 'public', table: '${resourceId}' },
@@ -251,7 +251,7 @@ const ${listenerName} = supabase.channel('custom-update-channel')
js: {
language: "js",
code: `
-const ${listenerName} = supabase.channel('custom-delete-channel')
+const ${listenerName} = carbon.channel('custom-delete-channel')
.on(
'postgres_changes',
{ event: 'DELETE', schema: 'public', table: '${resourceId}' },
@@ -276,7 +276,7 @@ const ${listenerName} = supabase.channel('custom-delete-channel')
js: {
language: "js",
code: `
-const ${listenerName} = supabase.channel('custom-filter-channel')
+const ${listenerName} = carbon.channel('custom-filter-channel')
.on(
'postgres_changes',
{ event: '*', schema: 'public', table: '${resourceId}', filter: '${columnName}=eq.${value}' },
diff --git a/apps/erp/app/routes/x+/feedback.tsx b/apps/erp/app/routes/x+/feedback.tsx
index 93046e906a..546b2c4827 100644
--- a/apps/erp/app/routes/x+/feedback.tsx
+++ b/apps/erp/app/routes/x+/feedback.tsx
@@ -10,7 +10,7 @@ export const config = {
};
export async function action({ request }: ActionFunctionArgs) {
- const { userId } = await requirePermissions(request, {});
+ const { userId, companyId } = await requirePermissions(request, {});
const formData = await request.formData();
const validation = await validator(feedbackValidator).validate(formData);
@@ -26,7 +26,12 @@ export async function action({ request }: ActionFunctionArgs) {
const serviceRole = await getCarbonServiceRole();
const slackClient = getSlackClient();
- const [user, insertFeedback] = await Promise.all([
+ const [company, user, insertFeedback] = await Promise.all([
+ serviceRole
+ .from("company")
+ .select("slackChannel")
+ .eq("id", companyId)
+ .single(),
serviceRole
.from("user")
.select("firstName,lastName,email")
@@ -49,8 +54,16 @@ export async function action({ request }: ActionFunctionArgs) {
});
}
+ let channel = "#feedback";
+ if (company.data?.slackChannel) {
+ channel = company.data.slackChannel;
+ if (!channel.startsWith("#")) {
+ channel = `#${channel}`;
+ }
+ }
+
await slackClient.sendMessage({
- channel: "#feedback",
+ channel,
text: `New feedback submitted`,
blocks: [
{
diff --git a/apps/mes/app/routes/x+/feedback.tsx b/apps/mes/app/routes/x+/feedback.tsx
index d12976ad69..66bc77bc31 100644
--- a/apps/mes/app/routes/x+/feedback.tsx
+++ b/apps/mes/app/routes/x+/feedback.tsx
@@ -10,7 +10,7 @@ export const config = {
};
export async function action({ request }: ActionFunctionArgs) {
- const { userId } = await requirePermissions(request, {});
+ const { userId, companyId } = await requirePermissions(request, {});
const formData = await request.formData();
const validation = await validator(feedbackValidator).validate(formData);
@@ -26,7 +26,12 @@ export async function action({ request }: ActionFunctionArgs) {
const serviceRole = await getCarbonServiceRole();
const slackClient = getSlackClient();
- const [user, insertFeedback] = await Promise.all([
+ const [company, user, insertFeedback] = await Promise.all([
+ serviceRole
+ .from("company")
+ .select("slackChannel")
+ .eq("id", companyId)
+ .single(),
serviceRole
.from("user")
.select("firstName,lastName,email")
@@ -49,8 +54,16 @@ export async function action({ request }: ActionFunctionArgs) {
});
}
+ let channel = "#feedback";
+ if (company.data?.slackChannel) {
+ channel = company.data.slackChannel;
+ if (!channel.startsWith("#")) {
+ channel = `#${channel}`;
+ }
+ }
+
await slackClient.sendMessage({
- channel: "#feedback",
+ channel,
text: `New feedback submitted`,
blocks: [
{
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index f22957e4eb..c25af4dd69 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -2009,6 +2009,7 @@ export type Database = {
name: string
phone: string | null
postalCode: string | null
+ slackChannel: string | null
stateProvince: string | null
taxId: string | null
updatedBy: string | null
@@ -2030,6 +2031,7 @@ export type Database = {
name: string
phone?: string | null
postalCode?: string | null
+ slackChannel?: string | null
stateProvince?: string | null
taxId?: string | null
updatedBy?: string | null
@@ -2051,6 +2053,7 @@ export type Database = {
name?: string
phone?: string | null
postalCode?: string | null
+ slackChannel?: string | null
stateProvince?: string | null
taxId?: string | null
updatedBy?: string | null
@@ -28793,14 +28796,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -31649,14 +31652,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index f22957e4eb..c25af4dd69 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -2009,6 +2009,7 @@ export type Database = {
name: string
phone: string | null
postalCode: string | null
+ slackChannel: string | null
stateProvince: string | null
taxId: string | null
updatedBy: string | null
@@ -2030,6 +2031,7 @@ export type Database = {
name: string
phone?: string | null
postalCode?: string | null
+ slackChannel?: string | null
stateProvince?: string | null
taxId?: string | null
updatedBy?: string | null
@@ -2051,6 +2053,7 @@ export type Database = {
name?: string
phone?: string | null
postalCode?: string | null
+ slackChannel?: string | null
stateProvince?: string | null
taxId?: string | null
updatedBy?: string | null
@@ -28793,14 +28796,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -31649,14 +31652,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
diff --git a/packages/database/supabase/migrations/20250213140548_slack-channel.sql b/packages/database/supabase/migrations/20250213140548_slack-channel.sql
new file mode 100644
index 0000000000..38536dbd2b
--- /dev/null
+++ b/packages/database/supabase/migrations/20250213140548_slack-channel.sql
@@ -0,0 +1 @@
+ALTER TABLE "company" ADD COLUMN "slackChannel" TEXT;