-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
400 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@comet/cms-admin": minor | ||
"@comet/blocks-api": minor | ||
"@comet/cms-site": minor | ||
"@comet/cms-api": minor | ||
--- | ||
|
||
Add PhoneLinkBlock and EmailLinkBlock |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
import { ExternalLinkBlock } from "@comet/blocks-api"; | ||
import { EmailLinkBlock, ExternalLinkBlock, PhoneLinkBlock } from "@comet/blocks-api"; | ||
import { createLinkBlock, DamFileDownloadLinkBlock, InternalLinkBlock } from "@comet/cms-api"; | ||
import { NewsLinkBlock } from "@src/news/blocks/news-link.block"; | ||
|
||
export const LinkBlock = createLinkBlock({ | ||
supportedBlocks: { internal: InternalLinkBlock, external: ExternalLinkBlock, news: NewsLinkBlock, damFileDownload: DamFileDownloadLinkBlock }, | ||
supportedBlocks: { | ||
internal: InternalLinkBlock, | ||
external: ExternalLinkBlock, | ||
news: NewsLinkBlock, | ||
damFileDownload: DamFileDownloadLinkBlock, | ||
phone: PhoneLinkBlock, | ||
email: EmailLinkBlock, | ||
}, | ||
}); |
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,80 @@ | ||
import { Field, FinalFormInput } from "@comet/admin"; | ||
import { BlockCategory, BlockInterface, BlocksFinalForm, createBlockSkeleton, SelectPreviewComponent } from "@comet/blocks-admin"; | ||
import * as React from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
interface EmailLinkBlockData { | ||
email?: string; | ||
} | ||
|
||
interface EmailLinkBlockInput { | ||
email?: string; | ||
} | ||
|
||
export const EmailLinkBlock: BlockInterface<EmailLinkBlockData, EmailLinkBlockData, EmailLinkBlockInput> = { | ||
...createBlockSkeleton(), | ||
|
||
name: "Email", | ||
|
||
displayName: <FormattedMessage id="comet.blocks.link.email" defaultMessage="Email" />, | ||
|
||
defaultValues: () => ({ email: undefined }), | ||
|
||
category: BlockCategory.Navigation, | ||
|
||
input2State: (state) => { | ||
return state; | ||
}, | ||
|
||
state2Output: (state) => { | ||
return { | ||
email: state.email, | ||
}; | ||
}, | ||
|
||
output2State: async (output) => { | ||
return { | ||
email: output.email, | ||
}; | ||
}, | ||
|
||
isValid: (state) => { | ||
return state.email ? isEmail(state.email) : true; | ||
}, | ||
|
||
AdminComponent: ({ state, updateState }) => { | ||
return ( | ||
<SelectPreviewComponent> | ||
<BlocksFinalForm | ||
onSubmit={(newState: EmailLinkBlockData) => { | ||
updateState((prevState) => ({ ...prevState, ...newState })); | ||
}} | ||
initialValues={state} | ||
> | ||
<Field | ||
label={<FormattedMessage id="comet.blocks.link.email" defaultMessage="Email" />} | ||
name="email" | ||
component={FinalFormInput} | ||
fullWidth | ||
validate={(email: string) => { | ||
if (email && !isEmail(email)) { | ||
return <FormattedMessage id="comet.blocks.link.email.invalid" defaultMessage="Invalid e-mail address" />; | ||
} | ||
}} | ||
/> | ||
</BlocksFinalForm> | ||
</SelectPreviewComponent> | ||
); | ||
}, | ||
previewContent: (state) => { | ||
return state.email ? [{ type: "text", content: state.email }] : []; | ||
}, | ||
}; | ||
|
||
const isEmail = (text: string) => { | ||
return !!String(text) | ||
.toLowerCase() | ||
.match( | ||
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/, | ||
); | ||
}; |
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,76 @@ | ||
import { Field, FinalFormInput } from "@comet/admin"; | ||
import { BlockCategory, BlockInterface, BlocksFinalForm, createBlockSkeleton, SelectPreviewComponent } from "@comet/blocks-admin"; | ||
import * as React from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
interface PhoneLinkBlockData { | ||
phone: string; | ||
} | ||
|
||
interface PhoneLinkBlockInput { | ||
phone: string; | ||
} | ||
|
||
export const PhoneLinkBlock: BlockInterface<PhoneLinkBlockData, PhoneLinkBlockData, PhoneLinkBlockInput> = { | ||
...createBlockSkeleton(), | ||
|
||
name: "Phone", | ||
|
||
displayName: <FormattedMessage id="comet.blocks.link.phone" defaultMessage="Phone Number" />, | ||
|
||
defaultValues: () => ({ phone: "" }), | ||
|
||
category: BlockCategory.Navigation, | ||
|
||
input2State: (state) => { | ||
return state; | ||
}, | ||
|
||
state2Output: (state) => { | ||
return { | ||
phone: state.phone, | ||
}; | ||
}, | ||
|
||
output2State: async (output) => { | ||
return { | ||
phone: output.phone, | ||
}; | ||
}, | ||
|
||
isValid: (state) => { | ||
return state.phone ? isPhone(state.phone) : true; | ||
}, | ||
|
||
AdminComponent: ({ state, updateState }) => { | ||
return ( | ||
<SelectPreviewComponent> | ||
<BlocksFinalForm | ||
onSubmit={(newState: PhoneLinkBlockData) => { | ||
updateState((prevState) => ({ ...prevState, ...newState })); | ||
}} | ||
initialValues={state} | ||
> | ||
<Field | ||
label={<FormattedMessage id="comet.blocks.link.phone" defaultMessage="Phone Number" />} | ||
name="phone" | ||
component={FinalFormInput} | ||
fullWidth | ||
validate={(phone: string) => { | ||
if (phone && !isPhone(phone)) { | ||
return <FormattedMessage id="comet.blocks.link.phone.invalid" defaultMessage="Invalid phone number" />; | ||
} | ||
}} | ||
/> | ||
</BlocksFinalForm> | ||
</SelectPreviewComponent> | ||
); | ||
}, | ||
previewContent: (state) => { | ||
return state.phone ? [{ type: "text", content: state.phone }] : []; | ||
}, | ||
}; | ||
|
||
const isPhone = (text: string) => { | ||
return !!String(text).match(/^[+]?[0-9]{4,20}$/im); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { IsEmail, IsOptional } from "class-validator"; | ||
|
||
import { BlockData, BlockInput, createBlock, inputToData } from "./block"; | ||
import { BlockField } from "./decorators/field"; | ||
|
||
class EmailLinkBlockData extends BlockData { | ||
@BlockField({ nullable: true }) | ||
email?: string; | ||
} | ||
|
||
class EmailLinkBlockInput extends BlockInput { | ||
@IsOptional() | ||
@IsEmail() | ||
@BlockField({ nullable: true }) | ||
email?: string; | ||
|
||
transformToBlockData(): EmailLinkBlockData { | ||
return inputToData(EmailLinkBlockData, this); | ||
} | ||
} | ||
|
||
export const EmailLinkBlock = createBlock(EmailLinkBlockData, EmailLinkBlockInput, "EmailLink"); |
Oops, something went wrong.