-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Email Link and Phone Link (in Action Block) #236
Open
jbmoelker
wants to merge
4
commits into
main
Choose a base branch
from
feat/email-and-phone-links
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bd790cc
feat(ActionBlock): add ExternalLink
jbmoelker e3fcb93
feat(ActionBlock): PhoneLink (tel, sms, email)
jbmoelker 8a907e7
feat(ActionBlock): Email Link (optional subject & body)
jbmoelker eeb8b8f
refactor: remove (useless) phone package
jbmoelker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { SimpleSchemaTypes } from '@datocms/cli/lib/cma-client-node'; | ||
|
||
export const actionStyleField: SimpleSchemaTypes.FieldCreateSchema = { | ||
label: 'Style', | ||
field_type: 'string', | ||
api_key: 'style', | ||
validators: { | ||
required: {}, | ||
enum: { values: ['default', 'primary', 'secondary'] }, | ||
}, | ||
appearance: { | ||
addons: [], | ||
editor: 'string_select', | ||
parameters: { | ||
options: [ | ||
{ hint: '', label: 'Default action', value: 'default' }, | ||
{ hint: '', label: 'Primary action', value: 'primary' }, | ||
{ hint: '', label: 'Secondary action', value: 'secondary' }, | ||
], | ||
}, | ||
}, | ||
default_value: 'default', | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import type { Client } from '@datocms/cli/lib/cma-client-node'; | ||
import { actionStyleField } from '../lib/fields'; | ||
|
||
export default async function (client: Client) { | ||
console.log('Create new models/block models'); | ||
|
||
console.log( | ||
'Create block model "\uD83D\uDD17 External Link" (`external_link`)' | ||
); | ||
await client.itemTypes.create( | ||
{ | ||
id: 'Yk1ge9eTTf25Iwph1Dx3_g', | ||
name: '\uD83D\uDD17 External Link', | ||
api_key: 'external_link', | ||
modular_block: true, | ||
inverse_relationships_enabled: false, | ||
}, | ||
{ | ||
skip_menu_item_creation: true, | ||
schema_menu_item_id: 'OiBwyNPrR82ZWMawg47csg', | ||
} | ||
); | ||
|
||
console.log('Creating new fields/fieldsets'); | ||
|
||
console.log( | ||
'Create Single-line string field "Title" (`title`) in block model "\uD83D\uDD17 External Link" (`external_link`)' | ||
); | ||
await client.fields.create('Yk1ge9eTTf25Iwph1Dx3_g', { | ||
id: 'Epmmtd7MTfeqpiwLP23D1Q', | ||
label: 'Title', | ||
field_type: 'string', | ||
api_key: 'title', | ||
validators: { required: {} }, | ||
appearance: { | ||
addons: [], | ||
editor: 'single_line', | ||
parameters: { heading: false, placeholder: null }, | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "URL" (`url`) in block model "\uD83D\uDD17 External Link" (`external_link`)' | ||
); | ||
await client.fields.create('Yk1ge9eTTf25Iwph1Dx3_g', { | ||
id: 'bUvYLCENQ3SP_vGhoN07nA', | ||
label: 'URL', | ||
field_type: 'string', | ||
api_key: 'url', | ||
validators: { required: {}, format: { predefined_pattern: 'url' } }, | ||
appearance: { | ||
addons: [], | ||
editor: 'single_line', | ||
parameters: { heading: false, placeholder: null }, | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Boolean field "Open in new tab" (`open_in_new_tab`) in block model "\uD83D\uDD17 External Link" (`external_link`)' | ||
); | ||
await client.fields.create('Yk1ge9eTTf25Iwph1Dx3_g', { | ||
id: 'AlPRQFQdRlixBp4Tgz5qsQ', | ||
label: 'Open in new tab', | ||
field_type: 'boolean', | ||
api_key: 'open_in_new_tab', | ||
appearance: { addons: [], editor: 'boolean', parameters: {} }, | ||
default_value: false, | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "Style" (`style`) in block model "\uD83D\uDD17 External Link" (`external_link`)' | ||
); | ||
await client.fields.create('Yk1ge9eTTf25Iwph1Dx3_g', { | ||
id: 'TNl63OntSe6ZLD3wCYxK-g', | ||
...actionStyleField, | ||
}); | ||
|
||
console.log('Update existing fields/fieldsets'); | ||
|
||
console.log( | ||
'Update Modular Content (Multiple blocks) field "Items" (`items`) in block model "\uD83C\uDF9B\uFE0F Action Block" (`action_block`)' | ||
); | ||
await client.fields.update('dAUckF8qR0edf_f7zam6hA', { | ||
validators: { | ||
rich_text_blocks: { | ||
item_types: ['GWnhoQDqQoGJj4-sQTVttw', 'Yk1ge9eTTf25Iwph1Dx3_g'], | ||
}, | ||
size: { min: 1 }, | ||
}, | ||
}); | ||
} |
235 changes: 235 additions & 0 deletions
235
config/datocms/migrations/1735398092_emailAndPhoneLinks.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,235 @@ | ||
import type { Client } from '@datocms/cli/lib/cma-client-node'; | ||
import { actionStyleField } from '../lib/fields'; | ||
|
||
export default async function (client: Client) { | ||
console.log('Manage upload filters'); | ||
|
||
console.log('Install plugin "Dropdown Conditional Fields"'); | ||
await client.plugins.create({ | ||
id: 'Srdwo4YOREmRtvMAV2otlQ', | ||
package_name: 'datocms-plugin-dropdown-conditional-fields', | ||
}); | ||
await client.plugins.update('Srdwo4YOREmRtvMAV2otlQ', { | ||
parameters: { developmentMode: false }, | ||
}); | ||
|
||
console.log('Create new models/block models'); | ||
|
||
console.log('Create block model "\uD83D\uDCDE Phone Link" (`phone_link`)'); | ||
await client.itemTypes.create( | ||
{ | ||
id: 'C5fWG5CYRJ69oqaP6CjYdA', | ||
name: '\uD83D\uDCDE Phone Link', | ||
api_key: 'phone_link', | ||
modular_block: true, | ||
inverse_relationships_enabled: false, | ||
}, | ||
{ | ||
skip_menu_item_creation: true, | ||
schema_menu_item_id: 'YNbDA4R-Srqf0u4-Rya3Ug', | ||
} | ||
); | ||
|
||
console.log('Create block model "\uD83D\uDCE7 Email Link" (`email_link`)'); | ||
await client.itemTypes.create( | ||
{ | ||
id: 'b90_c2zeS6auRELEzZHNcA', | ||
name: '\uD83D\uDCE7 Email Link', | ||
api_key: 'email_link', | ||
modular_block: true, | ||
inverse_relationships_enabled: false, | ||
}, | ||
{ | ||
skip_menu_item_creation: true, | ||
schema_menu_item_id: 'Vgf9ZeHvTqeh-tMAks2jFw', | ||
} | ||
); | ||
|
||
console.log('Creating new fields/fieldsets'); | ||
|
||
console.log( | ||
'Create Single-line string field "Title" (`title`) in block model "\uD83D\uDCDE Phone Link" (`phone_link`)' | ||
); | ||
await client.fields.create('C5fWG5CYRJ69oqaP6CjYdA', { | ||
id: 'fp9Cugu8QlKqawis3QTnPA', | ||
label: 'Title', | ||
field_type: 'string', | ||
api_key: 'title', | ||
validators: { required: {} }, | ||
appearance: { | ||
addons: [], | ||
editor: 'single_line', | ||
parameters: { heading: false, placeholder: null }, | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "Phone number" (`phone_number`) in block model "\uD83D\uDCDE Phone Link" (`phone_link`)' | ||
); | ||
await client.fields.create('C5fWG5CYRJ69oqaP6CjYdA', { | ||
id: 'bfnOOp5cSM-x8S5RKEpKsw', | ||
label: 'Phone number', | ||
field_type: 'string', | ||
api_key: 'phone_number', | ||
hint: 'Best to use international notation: +31 20 2610954', | ||
validators: { required: {} }, | ||
appearance: { | ||
addons: [], | ||
editor: 'single_line', | ||
parameters: { heading: false, placeholder: null }, | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "Action" (`action`) in block model "\uD83D\uDCDE Phone Link" (`phone_link`)' | ||
); | ||
await client.fields.create('C5fWG5CYRJ69oqaP6CjYdA', { | ||
id: 'ZbVIU9fdQgG8IFcEqIQ54A', | ||
label: 'Action', | ||
field_type: 'string', | ||
api_key: 'action', | ||
validators: { required: {}, enum: { values: ['call', 'sms', 'whatsapp'] } }, | ||
appearance: { | ||
addons: [ | ||
{ | ||
id: 'Srdwo4YOREmRtvMAV2otlQ', | ||
parameters: { | ||
dependencies: | ||
'{\n "sms": [\n "text"\n ],\n "whatsapp": [\n "text"\n ]\n}', | ||
}, | ||
}, | ||
], | ||
editor: 'string_select', | ||
parameters: { | ||
options: [ | ||
{ hint: '', label: 'Call', value: 'call' }, | ||
{ hint: '', label: 'Text (sms)', value: 'sms' }, | ||
{ hint: '', label: 'WhatsApp', value: 'whatsapp' }, | ||
], | ||
}, | ||
}, | ||
default_value: 'call', | ||
}); | ||
|
||
console.log( | ||
'Create Multiple-paragraph text field "Text" (`text`) in block model "\uD83D\uDCDE Phone Link" (`phone_link`)' | ||
); | ||
await client.fields.create('C5fWG5CYRJ69oqaP6CjYdA', { | ||
id: 'FKNWfZ5FS-KwBcWn9H8C7A', | ||
label: 'Text', | ||
field_type: 'text', | ||
api_key: 'text', | ||
validators: { sanitized_html: { sanitize_before_validation: true } }, | ||
appearance: { | ||
addons: [], | ||
editor: 'textarea', | ||
parameters: { placeholder: null }, | ||
type: 'textarea', | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "Style" (`style`) in block model "\uD83D\uDCDE Phone Link" (`phone_link`)' | ||
); | ||
await client.fields.create('C5fWG5CYRJ69oqaP6CjYdA', { | ||
id: 'GnHv18BPRyCsFsCAGmX0cQ', | ||
...actionStyleField, | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "Title" (`title`) in block model "\uD83D\uDCE7 Email Link" (`email_link`)' | ||
); | ||
await client.fields.create('b90_c2zeS6auRELEzZHNcA', { | ||
id: 'RM3FgSTnT4W5lYs16ndS9Q', | ||
label: 'Title', | ||
field_type: 'string', | ||
api_key: 'title', | ||
validators: { required: {} }, | ||
appearance: { | ||
addons: [], | ||
editor: 'single_line', | ||
parameters: { heading: false, placeholder: null }, | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "Email address" (`email_address`) in block model "\uD83D\uDCE7 Email Link" (`email_link`)' | ||
); | ||
await client.fields.create('b90_c2zeS6auRELEzZHNcA', { | ||
id: 'VpbcpEhCS5OjLjrdUU8Z6w', | ||
label: 'Email address', | ||
field_type: 'string', | ||
api_key: 'email_address', | ||
validators: { required: {}, format: { predefined_pattern: 'email' } }, | ||
appearance: { | ||
addons: [], | ||
editor: 'single_line', | ||
parameters: { heading: false, placeholder: null }, | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "Email Subject" (`email_subject`) in block model "\uD83D\uDCE7 Email Link" (`email_link`)' | ||
); | ||
await client.fields.create('b90_c2zeS6auRELEzZHNcA', { | ||
id: 'LMloAtp6SxOTDuaxCQ7L9g', | ||
label: 'Email Subject', | ||
field_type: 'string', | ||
api_key: 'email_subject', | ||
appearance: { | ||
addons: [], | ||
editor: 'single_line', | ||
parameters: { heading: false, placeholder: null }, | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Multiple-paragraph text field "Email Body" (`email_body`) in block model "\uD83D\uDCE7 Email Link" (`email_link`)' | ||
); | ||
await client.fields.create('b90_c2zeS6auRELEzZHNcA', { | ||
id: 'DvV-XIMvT-eioHVaY6AOeQ', | ||
label: 'Email Body', | ||
field_type: 'text', | ||
api_key: 'email_body', | ||
appearance: { | ||
addons: [], | ||
editor: 'textarea', | ||
parameters: { placeholder: null }, | ||
type: 'textarea', | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "Style" (`style`) in block model "\uD83D\uDCE7 Email Link" (`email_link`)' | ||
); | ||
await client.fields.create('b90_c2zeS6auRELEzZHNcA', { | ||
id: 'OAAORe89QV-DoOO1GfG5Jw', | ||
...actionStyleField, | ||
}); | ||
|
||
console.log('Update existing fields/fieldsets'); | ||
|
||
console.log( | ||
'Update Modular Content (Multiple blocks) field "Items" (`items`) in block model "\uD83C\uDF9B\uFE0F Action Block" (`action_block`)' | ||
); | ||
await client.fields.update('dAUckF8qR0edf_f7zam6hA', { | ||
validators: { | ||
rich_text_blocks: { | ||
item_types: [ | ||
'C5fWG5CYRJ69oqaP6CjYdA', | ||
'GWnhoQDqQoGJj4-sQTVttw', | ||
'Yk1ge9eTTf25Iwph1Dx3_g', | ||
'b90_c2zeS6auRELEzZHNcA', | ||
], | ||
}, | ||
size: { min: 1 }, | ||
}, | ||
}); | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could add more validation here, but validating phone numbers can be tricky. Editors can also just try if the number the entered, works in the preview.
Even more nice to have would be a Phone Input Field as a DatoCMS plugin. We could create that based on
react-phone-number-input
. Pinging @velomovies ;)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would even go as far as saying this feature can be implemented just by adding a plugin, right? They're all links..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarleenEliza mentioned that my assumption was incorrect,
mailto:
etc are note valid URLs according to Dato.