-
Notifications
You must be signed in to change notification settings - Fork 0
Manage multiple cta in service create update #1363
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
base: master
Are you sure you want to change the base?
Changes from 8 commits
8856cd6
e1040c1
696bda1
86a85bf
a788665
7f46072
5458e35
35b826d
6085977
fb8f046
8d18988
14240eb
02f8204
4bd1d91
a94705a
3531379
573d444
1333e39
d6fef96
e0e85fe
ffc5eb5
082826d
a8a0e6a
38049c3
01a4a71
4f7c2a4
bd79f3c
6b12c2f
e63f51a
3e4a732
94e83a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"io-services-cms-backoffice": minor | ||
--- | ||
|
||
Added secondary CTA and improved CTA management for created/modified services |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { AddCircleOutline, RemoveCircleOutline } from "@mui/icons-material"; | ||
import { Button, Grid } from "@mui/material"; | ||
import React from "react"; | ||
|
||
export interface CtaControlsRowProps { | ||
addLabel: string; | ||
initialStateRemove?: boolean; | ||
onAdd?: () => void; | ||
onRemove?: () => void; | ||
removeLabel: string; | ||
show?: boolean; | ||
} | ||
|
||
export const CtaControlsButtons: React.FC<CtaControlsRowProps> = ({ | ||
addLabel, | ||
initialStateRemove = false, | ||
onAdd, | ||
onRemove, | ||
removeLabel, | ||
show = true, | ||
}) => { | ||
if (!show) return null; | ||
|
||
return ( | ||
<> | ||
<Grid item md={6} xs={12}> | ||
{initialStateRemove ? ( | ||
<Button | ||
color="error" | ||
onClick={onRemove} | ||
startIcon={<RemoveCircleOutline />} | ||
variant="text" | ||
> | ||
{removeLabel} | ||
</Button> | ||
) : ( | ||
<Button | ||
color="primary" | ||
onClick={onAdd} | ||
startIcon={<AddCircleOutline />} | ||
variant="text" | ||
> | ||
{addLabel} | ||
</Button> | ||
)} | ||
</Grid> | ||
<Grid item md={6} xs={12} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default CtaControlsButtons; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { Banner } from "@/components/banner"; | ||
import { FormStepSectionWrapper } from "@/components/forms"; | ||
import { | ||
SelectController, | ||
TextFieldController, | ||
UrlFieldController, | ||
} from "@/components/forms/controllers"; | ||
import { Link, ReportProblemRounded } from "@mui/icons-material"; | ||
import { Box, Divider, Grid } from "@mui/material"; | ||
import { useTranslation } from "next-i18next"; | ||
import React from "react"; | ||
import { useFormContext } from "react-hook-form"; | ||
|
||
import CtaControlsButtons from "./cta-controls-buttons"; | ||
|
||
export const ServiceCtaManager: React.FC = () => { | ||
const { t } = useTranslation(); | ||
const { clearErrors, setValue, watch } = useFormContext(); | ||
|
||
const hasCta2PreUrl = watch("metadata.cta.cta_2.preUrl"); | ||
const initialStateBtn = hasCta2PreUrl !== "" ? true : false; | ||
const selectItems = [ | ||
{ | ||
label: t("forms.service.extraConfig.cta.form.externalLink"), | ||
value: "iohandledlink://", | ||
giuseppedipinto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}, | ||
{ | ||
label: t("forms.service.extraConfig.cta.form.singleSignOn"), | ||
value: "iosso://", | ||
}, | ||
{ | ||
label: t("forms.service.extraConfig.cta.form.internalLink"), | ||
value: "ioit://", | ||
}, | ||
]; | ||
|
||
const linkCtaType = ["iohandledlink://", "iosso://", "ioit://"]; | ||
|
||
const renderCtaSection = (slot: "cta_1" | "cta_2") => { | ||
//let us observe the value of the select stored referring to the current slot | ||
const kind = watch(`metadata.cta.${slot}.preUrl`); | ||
|
||
const helperCtaInternal = | ||
|
||
kind === linkCtaType[2] ? ( | ||
<span | ||
dangerouslySetInnerHTML={{ | ||
__html: t("forms.service.metadata.cta.text.helperText"), | ||
}} | ||
/> | ||
) : undefined; | ||
|
||
const labelCtaInternal = | ||
|
||
kind === linkCtaType[2] | ||
? t("forms.service.metadata.cta.url.labelInternal") | ||
: t("forms.service.metadata.cta.url.label"); | ||
|
||
return ( | ||
<> | ||
<Grid columnSpacing={2} container rowSpacing={1}> | ||
<Grid item md={6} xs={12}> | ||
<SelectController | ||
displayEmpty | ||
helperText={helperCtaInternal} | ||
items={selectItems} | ||
label={t("forms.service.extraConfig.cta.form.selectLabel")} | ||
name={`metadata.cta.${slot}.preUrl`} | ||
/> | ||
</Grid> | ||
|
||
<Grid item md={6} xs={12} /> | ||
|
||
{kind === linkCtaType[1] && ( | ||
<Grid item xs={12}> | ||
<Banner | ||
description={t( | ||
"forms.service.extraConfig.cta.form.btnWithLink.alertSingleSignOn", | ||
)} | ||
icon={<ReportProblemRounded />} | ||
severity="warning" | ||
/> | ||
</Grid> | ||
)} | ||
|
||
<Grid item md={6} xs={12}> | ||
<TextFieldController | ||
label={t("forms.service.metadata.cta.text.label")} | ||
name={`metadata.cta.${slot}.text`} | ||
placeholder={t("forms.service.metadata.cta.text.placeholder")} | ||
/> | ||
</Grid> | ||
|
||
<Grid item md={6} xs={12}> | ||
<UrlFieldController | ||
hideCheckUrl={kind === linkCtaType[0] ? false : true} | ||
label={labelCtaInternal} | ||
name={`metadata.cta.${slot}.url`} | ||
placeholder={t("forms.service.metadata.cta.url.placeholder")} | ||
/> | ||
</Grid> | ||
{ | ||
<CtaControlsButtons | ||
addLabel={t("forms.service.extraConfig.cta.addSecondaryButton")} | ||
initialStateRemove={initialStateBtn} | ||
onAdd={addSecondary} | ||
onRemove={removeSecondary} | ||
removeLabel={t( | ||
"forms.service.extraConfig.cta.removeSecondaryButton", | ||
)} | ||
show={slot === "cta_1" && hasCta2PreUrl !== "" ? false : true} | ||
/> | ||
} | ||
</Grid> | ||
</> | ||
); | ||
}; | ||
|
||
const addSecondary = () => { | ||
setValue( | ||
"metadata.cta.cta_2", | ||
{ | ||
preUrl: "iohandledlink://", | ||
text: "", | ||
url: "", | ||
}, | ||
{ shouldDirty: true, shouldValidate: true }, | ||
); | ||
}; | ||
|
||
const removeSecondary = () => { | ||
setValue("metadata.cta.cta_2.preUrl", ""); | ||
setValue("metadata.cta.cta_2.text", ""); | ||
setValue("metadata.cta.cta_2.url", ""); | ||
clearErrors(["metadata.cta.cta_2"]); | ||
}; | ||
return ( | ||
<Box> | ||
<FormStepSectionWrapper | ||
description={t("forms.service.extraConfig.cta.description")} | ||
icon={<Link />} | ||
title={t("forms.service.extraConfig.cta.label")} | ||
> | ||
{renderCtaSection("cta_1")} | ||
{hasCta2PreUrl !== "" ? ( | ||
<Box mt={2}> | ||
<Divider /> | ||
{renderCtaSection("cta_2")} | ||
</Box> | ||
) : null} | ||
</FormStepSectionWrapper> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ServiceCtaManager; |
Uh oh!
There was an error while loading. Please reload this page.