Skip to content
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

Remove drafts compilation tool #163

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pages/UxDashboard/ResultsPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const ResultsPage = () => {
saveDashboard({
campaign: id,
body: {
status: "publish",
visible: 1,
},
})
.unwrap()
Expand Down
168 changes: 66 additions & 102 deletions src/pages/UxDashboard/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,23 @@
import {
Card,
Button,
Text,
Steps,
} from "@appquality/appquality-design-system";
import { Button, Card, Steps } from "@appquality/appquality-design-system";
import { useFormikContext } from "formik";
import { FormValuesInterface } from "./UxForm/FormProvider";
import { usePatchCampaignsByCampaignUxMutation } from "src/services/tryberApi";
import { useParams } from "react-router-dom";
import siteWideMessageStore from "src/redux/siteWideMessages";
import { usePatchCampaignsByCampaignUxMutation } from "src/services/tryberApi";
import { useAppDispatch, useAppSelector } from "src/store";
import {
setCurrentFormSection,
setCurrentStep,
setIsProgrammaticallyScrolling,
setPublishStatus,
} from "./uxDashboardSlice";
import { FormValuesInterface } from "./UxForm/FormProvider";

const Sidebar = () => {
const { id } = useParams<{ id: string }>();
const { add } = siteWideMessageStore();
const { submitForm, values, isSubmitting, isValid } =
useFormikContext<FormValuesInterface>();
const [saveDashboard] = usePatchCampaignsByCampaignUxMutation();
const { currentStep, currentFormSection, publishStatus } = useAppSelector(
const { currentFormSection, publishStatus } = useAppSelector(
(state) => state.uxDashboard
);
const dispatch = useAppDispatch();
Expand All @@ -38,102 +32,72 @@ const Sidebar = () => {
}
};

if (currentStep >= 2) return null;
const handlePublish = async () => {
dispatch(setPublishStatus("publishing"));
await saveDashboard({
campaign: id,
body: {
visible: values.visible === 1 ? 0 : 1,
},
})
.unwrap()
.then((res) => {
dispatch(setPublishStatus("success"));
add({
type: "success",
message: `Dashboard published`,
expire: 5,
});
})
.catch((err) => {
dispatch(setPublishStatus("failed"));
});
};
return (
<div className="stick-to-header-lg">
<Card title="Azioni" className="aq-mb-3">
{currentStep === 0 && (
<>
<Button
className="aq-mb-4"
kind="primary"
flat
size="block"
type="submit"
data-qa="submit-draft"
disabled={isSubmitting}
onClick={handleSaveDraft}
>
Save Draft
</Button>
<Text className="aq-mb-2">
Per pubblicare passa prima dalla preview
</Text>
<Button
type="button"
size="block"
kind="secondary"
data-qa="open-dashboard-preview"
onClick={() => dispatch(setCurrentStep(1))}
disabled={typeof values.status === "undefined" || isSubmitting}
>
Preview
</Button>
</>
)}
{currentStep === 1 && (
<>
<Button
className="aq-mb-4"
kind="primary"
flat
size="block"
data-qa="close-dashboard-preview"
onClick={() => dispatch(setCurrentStep(0))}
>
Torna alle modifiche
</Button>
<Text className="aq-mb-2">
Pubblica per rendere disponibile la dashboard anche al cliente
</Text>
<Button
type="button"
size="block"
kind="secondary"
data-qa="publish-dashboard"
disabled={publishStatus === "publishing"}
onClick={() => {
dispatch(setPublishStatus("publishing"));
saveDashboard({
campaign: id,
body: {
status: "publish",
},
})
.unwrap()
.then((res) => {
dispatch(setPublishStatus("success"));
})
.catch((err) => {
dispatch(setPublishStatus("failed"));
})
.finally(() => {
dispatch(setCurrentStep(2));
});
}}
>
Pubblica
</Button>
</>
)}
</Card>
{currentStep === 0 && (
<Card title="Sezioni del form" className="aq-mb-3">
<Steps
direction="vertical"
current={currentFormSection}
clickHandler={(index, current) => {
if (index === current) return;
dispatch(setCurrentFormSection(index));
dispatch(setIsProgrammaticallyScrolling(true));
}}
<>
<Button
className="aq-mb-4"
kind="primary"
flat
size="block"
type="submit"
data-qa="submit-draft"
disabled={isSubmitting}
onClick={handleSaveDraft}
>
Salva
</Button>

<Button
type="button"
size="block"
kind="secondary"
data-qa="publish-dashboard"
disabled={
publishStatus === "publishing" || values.visible === undefined
}
onClick={handlePublish}
>
<Steps.Step title="Sulla Campagna" />
<Steps.Step title="Panoramica" />
<Steps.Step title="Nel dettaglio" />
</Steps>
</Card>
)}
{values.visible === 0 ? "Pubblica" : "Nascondi"}
</Button>
</>
</Card>
<Card title="Sezioni del form" className="aq-mb-3">
<Steps
direction="vertical"
current={currentFormSection}
clickHandler={(index, current) => {
if (index === current) return;
dispatch(setCurrentFormSection(index));
dispatch(setIsProgrammaticallyScrolling(true));
}}
>
<Steps.Step title="Sulla Campagna" />
<Steps.Step title="Panoramica" />
</Steps>
</Card>
</div>
);
};
Expand Down
9 changes: 4 additions & 5 deletions src/pages/UxDashboard/UxForm/FormProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface FormSentiment {
comment: string;
}
export interface FormValuesInterface {
status?: GetCampaignsByCampaignUxApiResponse["status"];
visible?: GetCampaignsByCampaignUxApiResponse["visible"];
goal: GetCampaignsByCampaignUxApiResponse["goal"];
methodology: GetCampaignsByCampaignUxApiResponse["methodology"];
questions: FormQuestion[];
Expand All @@ -48,10 +48,9 @@ const FormProvider = ({ children }: { children: ReactNode }) => {
});
const { data: campaignData, isLoading: campaignDataLoading } =
useGetCampaignsByCampaignQuery({ campaign: id });

const initialValues: FormValuesInterface = useMemo(
() => ({
status: currentData?.status,
visible: currentData?.visible ?? undefined,
goal: currentData?.goal || "",
methodology: currentData?.methodology || {
name: campaignData?.type || "",
Expand Down Expand Up @@ -91,7 +90,7 @@ const FormProvider = ({ children }: { children: ReactNode }) => {
}

const validationSchema = object({
status: string(),
visible: number(),
goal: string().required("Campo obbligatorio"),
methodology: object().shape({
name: string(),
Expand Down Expand Up @@ -164,13 +163,13 @@ const FormProvider = ({ children }: { children: ReactNode }) => {
initialValues={initialValues}
enableReinitialize
onSubmit={async (values, formikHelpers) => {
// todo: better typing for values because validationSchema prevent usersNumber to be undefined
if (values.usersNumber === undefined) return;

formikHelpers.setSubmitting(true);
const res = await saveDashboard({
campaign: id,
body: {
visible: values.visible,
goal: values.goal,
questions: values.questions.map((question) => ({
id: question.id,
Expand Down
49 changes: 8 additions & 41 deletions src/pages/UxDashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@ import {
BSGrid,
Container,
PageTitle,
Steps,
Title,
} from "@appquality/appquality-design-system";
import { useParams } from "react-router-dom";
import ErrorUnauthorized from "src/features/ErrorUnauthorized/ErrorUnauthorized";
import { PageTemplate } from "src/features/PageTemplate";
import { useGetCampaignsByCampaignQuery } from "src/services/tryberApi";
import UxDashboardForm from "./UxForm";
import { useParams } from "react-router-dom";
import Preview from "./Preview";
import Sidebar from "./Sidebar";
import FormProvider from "./UxForm/FormProvider";
import ResultsPage from "./ResultsPage";
import { useAppSelector } from "src/store";
import styled from "styled-components";
import { PageTemplate } from "src/features/PageTemplate";
import Sidebar from "./Sidebar";
import useCanSee from "./useCanSee";

const StyledSteps = styled(Steps)`
.step-status-icon {
background-color: ${({ theme }) => theme.colors.gray100};
}
`;
import UxDashboardForm from "./UxForm";
import FormProvider from "./UxForm/FormProvider";

const ResponsiveCol = styled(BSCol)<{ lgOrder: number }>`
@media (min-width: ${({ theme }) => theme.grid.breakpoints.lg}) {
Expand All @@ -33,7 +23,6 @@ const ResponsiveCol = styled(BSCol)<{ lgOrder: number }>`

const UxDashboard = () => {
const { id } = useParams<{ id: string }>();
const { currentStep } = useAppSelector((state) => state.uxDashboard);

const { isError, isLoading, hasPermission } = useCanSee(id);

Expand All @@ -53,7 +42,6 @@ const UxDashboard = () => {
}

if (hasPermission) {
// todo: discuss about appq_video_dashboard permission (change tests)
return (
<PageTemplate>
<FormProvider>
Expand All @@ -69,35 +57,14 @@ const UxDashboard = () => {
>
Tool di compilazione
</PageTitle>
<Title size="xl">
Il CompilationTool è temporaneamente disabilitato. Contatta il
supporto se ha bisogno di effettuare modifiche.
{/* <BSGrid>
<BSGrid>
<ResponsiveCol size="col-lg-3" lgOrder={1}>
<Sidebar />
</ResponsiveCol>
<ResponsiveCol size="col-lg-9" lgOrder={0}>
<StyledSteps
current={currentStep}
className="aq-my-4"
direction="horizontal"
>
<StyledSteps.Step isCompleted={true} title={"Form"} />
<StyledSteps.Step
isCompleted={currentStep > 0}
title={"Preview"}
/>
<StyledSteps.Step
isCompleted={currentStep > 1}
title={"Publish"}
/>
</StyledSteps>
{currentStep === 0 && <UxDashboardForm />}
{currentStep === 1 && <Preview />}
{currentStep === 2 && <ResultsPage />}
<UxDashboardForm />
</ResponsiveCol>
</BSGrid> */}
</Title>
</BSGrid>
</Container>
</FormProvider>
</PageTemplate>
Expand Down
Loading
Loading