Skip to content

Commit

Permalink
feat: integrate everything needed for the livedemo
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveBunlon committed Sep 15, 2023
1 parent 11202d1 commit e3d8146
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 119 deletions.
72 changes: 36 additions & 36 deletions .forestadmin-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"fields": [
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "commission_rate",
"integration": null,
"inverseOf": null,
Expand All @@ -21,7 +21,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "created_at",
"integration": null,
"inverseOf": null,
Expand Down Expand Up @@ -54,7 +54,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "displayName",
"integration": null,
"inverseOf": null,
Expand All @@ -70,7 +70,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "end_at",
"integration": null,
"inverseOf": null,
Expand All @@ -86,7 +86,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "id",
"integration": null,
"inverseOf": null,
Expand All @@ -102,7 +102,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "start_at",
"integration": null,
"inverseOf": null,
Expand All @@ -118,7 +118,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "updated_at",
"integration": null,
"inverseOf": null,
Expand Down Expand Up @@ -173,7 +173,7 @@
"fields": [
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "created_at",
"integration": null,
"inverseOf": null,
Expand All @@ -189,7 +189,7 @@
},
{
"defaultValue": null,
"enums": ["lead", "customer", "ex-customer"],
"enums": ["customer", "ex-customer", "lead"],
"field": "customer_type",
"integration": null,
"inverseOf": null,
Expand Down Expand Up @@ -222,7 +222,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "email",
"integration": null,
"inverseOf": null,
Expand All @@ -238,7 +238,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "first_name",
"integration": null,
"inverseOf": null,
Expand All @@ -254,7 +254,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "id",
"integration": null,
"inverseOf": null,
Expand All @@ -270,7 +270,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "last_name",
"integration": null,
"inverseOf": null,
Expand All @@ -286,7 +286,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "phone",
"integration": null,
"inverseOf": null,
Expand All @@ -302,7 +302,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "updated_at",
"integration": null,
"inverseOf": null,
Expand Down Expand Up @@ -382,7 +382,7 @@
"fields": [
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "closed_at",
"integration": null,
"inverseOf": null,
Expand Down Expand Up @@ -415,7 +415,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "created_at",
"integration": null,
"inverseOf": null,
Expand Down Expand Up @@ -465,7 +465,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "id",
"integration": null,
"inverseOf": null,
Expand All @@ -481,7 +481,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "owner",
"integration": null,
"inverseOf": null,
Expand All @@ -497,7 +497,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "stage",
"integration": null,
"inverseOf": null,
Expand All @@ -513,7 +513,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "updated_at",
"integration": null,
"inverseOf": null,
Expand Down Expand Up @@ -543,7 +543,7 @@
"fields": [
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "address",
"integration": null,
"inverseOf": null,
Expand All @@ -559,7 +559,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "area",
"integration": null,
"inverseOf": null,
Expand All @@ -575,7 +575,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "city",
"integration": null,
"inverseOf": null,
Expand All @@ -591,7 +591,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "created_at",
"integration": null,
"inverseOf": null,
Expand Down Expand Up @@ -624,7 +624,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "description",
"integration": null,
"inverseOf": null,
Expand All @@ -640,7 +640,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "displayName",
"integration": null,
"inverseOf": null,
Expand All @@ -656,7 +656,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "id",
"integration": null,
"inverseOf": null,
Expand All @@ -672,7 +672,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "monthly_rent",
"integration": null,
"inverseOf": null,
Expand All @@ -688,7 +688,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "num_rooms",
"integration": null,
"inverseOf": null,
Expand All @@ -704,7 +704,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "picture",
"integration": null,
"inverseOf": null,
Expand All @@ -720,7 +720,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "updated_at",
"integration": null,
"inverseOf": null,
Expand All @@ -736,7 +736,7 @@
},
{
"defaultValue": null,
"enums": null,
"enums": [],
"field": "zip",
"integration": null,
"inverseOf": null,
Expand All @@ -762,10 +762,10 @@
"segments": []
}
],
"metadata": {
"meta": {
"liana": "forest-nodejs-agent",
"liana_version": "1.13.4",
"liana_version": "1.28.3",
"liana_features": null,
"stack": {"engine": "nodejs", "engine_version": "18.15.0"}
"stack": {"engine": "nodejs", "engine_version": "18.14.0"}
}
}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
.idea
.env
node_modules
24 changes: 21 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import type { SslMode } from '@forestadmin/datasource-sql';
import type { Schema } from './typings';

import 'dotenv/config';
import { createAgent } from '@forestadmin/agent';
import { ActionContext, createAgent } from '@forestadmin/agent';
import { createSqlDataSource } from '@forestadmin/datasource-sql';
import liveDemoBlocker, { blockActionForLiveDemoUser } from '@forestadmin-experimental/live-demo-blocker';

// This object allows to configure your Forest Admin panel
const agent = createAgent<Schema>({
Expand All @@ -30,6 +31,8 @@ agent.addDataSource(
}),
);

agent.use(liveDemoBlocker);

// SMART ACTIONS
// Deal
// TODO: add constraint stage has to be "new"
Expand All @@ -51,6 +54,9 @@ agent.customizeCollection('deal', collection => {
},
],
execute: async (context, resultBuilder) => {
const result = blockActionForLiveDemoUser(context as unknown as ActionContext, resultBuilder);
if (result) return result;

// Retrieve values entered in the form and columns from the selected record.
const { commission_rate, start_at } = context.formValues;
const { id, owner } = await context.getRecord([
Expand Down Expand Up @@ -80,6 +86,9 @@ agent.customizeCollection('deal', collection =>
collection.addAction('Close deal', {
scope: 'Bulk',
execute: async (context, resultBuilder) => {
const result = blockActionForLiveDemoUser(context as unknown as ActionContext, resultBuilder);
if (result) return result;

const now = new Date();
await context.collection.update(context.filter, { stage: 'closed', closed_at: now.toISOString() });
return resultBuilder.success('Deal closed !');
Expand All @@ -92,6 +101,9 @@ agent.customizeCollection('deal', collection =>
collection.addAction('Mark as rejected', {
scope: 'Bulk',
execute: async (context, resultBuilder) => {
const result = blockActionForLiveDemoUser(context as unknown as ActionContext, resultBuilder);
if (result) return result;

await context.collection.update(context.filter, { stage: 'rejected' });
return resultBuilder.success('Deal rejected: please add a note to explain why');
},
Expand All @@ -114,7 +126,10 @@ agent.customizeCollection('deal', collection =>
agent.customizeCollection('customer', collection =>
collection.addAction('Mark as customer', {
scope: 'Single',
execute: async context => {
execute: async (context, resultBuilder) => {
const result = blockActionForLiveDemoUser(context as unknown as ActionContext, resultBuilder);
if (result) return result;

await context.collection.update(context.filter, { customer_type: 'customer' });
},
}),
Expand All @@ -123,7 +138,10 @@ agent.customizeCollection('customer', collection =>
agent.customizeCollection('customer', collection =>
collection.addAction('Mark as ex-customer', {
scope: 'Single',
execute: async context => {
execute: async (context, resultBuilder) => {
const result = blockActionForLiveDemoUser(context as unknown as ActionContext, resultBuilder);
if (result) return result;

await context.collection.update(context.filter, { customer_type: 'ex-customer' });
},
}),
Expand Down
Loading

0 comments on commit e3d8146

Please sign in to comment.