Skip to content

Commit

Permalink
wip 1
Browse files Browse the repository at this point in the history
  • Loading branch information
JanJaroszczak committed Mar 26, 2024
1 parent 2512248 commit 1af4abd
Show file tree
Hide file tree
Showing 14 changed files with 388 additions and 12 deletions.
29 changes: 25 additions & 4 deletions govtool/frontend/src/components/atoms/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,27 @@ import { TextAreaProps } from "./types";
const TextAreaBase = styled(TextareaAutosize)(
() => `
font-family: "Poppins";
font-size: 16px;
font-weight: 400;
::placeholder {
font-family: "Poppins";
font-size: 16px;
font-weight: 400;
color: #a6a6a6;
}
`,
);

export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
({ errorMessage, maxLength = 500, onBlur, onFocus, ...props }, ref) => {
(
{
errorMessage,
maxLength = 500,
onBlur,
onFocus,
isModifiedLayout,
...props
},
ref,
) => {
const { isMobile } = useScreenDimension();
const textAraeRef = useRef<HTMLTextAreaElement>(null);

Expand Down Expand Up @@ -51,19 +59,32 @@ export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
[handleBlur, handleFocus],
);

const getTexAreaHeight = () => {
if (isModifiedLayout && isMobile) return "312px";
if (isModifiedLayout) return "208px";
if (isMobile) return "104px";
return "128px";
};

return (
<TextAreaBase
style={{
border: `1px solid ${errorMessage ? "red" : "#6F99FF"}`,
backgroundColor: errorMessage ? "#FAEAEB" : "white",
borderRadius: "24px",
height: isMobile ? "104px" : "128px",
height: getTexAreaHeight(),
outline: "none",
padding: "12px 14px",
resize: "none",
}}
maxLength={maxLength}
ref={textAraeRef}
sx={{
fontSize: isModifiedLayout ? "12px" : "auto",
"&::placeholder": {
fontSize: isModifiedLayout ? "12px" : "16px",
},
}}
{...props}
/>
);
Expand Down
1 change: 1 addition & 0 deletions govtool/frontend/src/components/atoms/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type FormHelpfulTextProps = {

export type TextAreaProps = TextareaAutosizeProps & {
errorMessage?: string;
isModifiedLayout?: boolean;
};

export type InfoTextProps = {
Expand Down
10 changes: 9 additions & 1 deletion govtool/frontend/src/components/molecules/Field/TextArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaFieldProps>(
} as unknown as HTMLTextAreaElement),
[handleBlur, handleFocus],
);

const getCounterBottomSxValue = () => {
if (props.isModifiedLayout && errorMessage) return 30;
if (props.isModifiedLayout) return 10;
if (errorMessage) return 52.5;
return 35;
};

return (
<Box
sx={{
Expand Down Expand Up @@ -92,7 +100,7 @@ export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaFieldProps>(
<Typography
color="#8E908E"
sx={{
bottom: errorMessage ? 52.5 : 35,
bottom: getCounterBottomSxValue(),
position: "absolute",
right: 15,
}}
Expand Down
22 changes: 22 additions & 0 deletions govtool/frontend/src/components/molecules/VoteActionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,28 @@ export const VoteActionForm = ({
</Button>
)}
{/* TODO: Change below into new voting context */}
<Button
variant="outlined"
onClick={() => {
openModal({
type: "voteContext",
state: {
status: "success",
cancelText: 'close',
title: t("modals.delegation.title"),
message: t("modals.delegation.message"),
link: "https://adanordic.com/latest_transactions",
buttonText: t("modals.common.goToDashboard"),
onSubmit: () => {
// navigate(PATHS.dashboard);
// closeModal();
},
dataTestId: "delegation-transaction-submitted-modal",
},
});
}}
>Provide context about your vote
</Button>
<Box
alignItems="center"
data-testid="context-button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ export const GovernanceActionDetailsCardData = ({
createdDate={createdDate}
expiryDate={expiryDate}
/>
{isDataMissing && (
<ExternalModalButton
url="https://dev-sanchonet.govtool.byron.network/"
label={t("govActions.seeExternalData")}
/>
)}
{/* {isDataMissing && ( */}
<ExternalModalButton
url="https://dev-sanchonet.govtool.byron.network/"
label={t("govActions.seeExternalData")}
/>
{/* )} */}
<GovernanceActionCardElement
label={t("govActions.submissionDate")}
text={createdDate}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { useState } from "react";

import { ModalWrapper } from "@atoms";
// import { useModal } from "@context";
import { useForm, FormProvider } from "react-hook-form";
import { VoteContextTerms, VoteContextText } from "@organisms";
// import { useScreenDimension, useTranslation } from "@hooks";
import { VoteContextFormValues } from "@/hooks/forms/useVoteContextForm";

// type VoteContextModalState = {
// onContinue?: () => void;
// onCancel?: () => void;
// };

export const VoteContextModal = () => {
const [step, setStep] = useState(1);

// const { state, closeModal } = useModal<VoteContextModalState>();

const methods = useForm<VoteContextFormValues>({ mode: "onChange" });

// console.log(errors, isValid);
// console.log("dupa", isValid);

return (
<ModalWrapper
dataTestId="vote-context-modal"
sx={{
maxWidth: "700px",
p: "60px 32px 32px",
}}
>
<FormProvider {...methods}>
{step === 1 && <VoteContextText setStep={setStep} />}
{step === 2 && <VoteContextTerms setStep={setStep} />}
</FormProvider>
{/* <Box
sx={{
display: "flex",
justifyContent: "space-between",
marginTop: "40px",
...(isMobile && { flexDirection: "column", gap: 3 }),
}}
>
<Button
data-testid="cancel-modal-button"
onClick={state?.onCancel ? state?.onCancel : closeModal}
size="large"
sx={{
width: isMobile ? "100%" : "154px",
}}
variant="outlined"
>
Cancel
</Button>
<Button
data-testid="confirm-modal-button"
disabled={!isValid}
onClick={() => {}}
size="large"
sx={{
width: isMobile ? "100%" : "154px",
}}
variant="contained"
>
Continue
</Button>
</Box> */}
</ModalWrapper>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Dispatch, SetStateAction } from "react";
import { Box, Link } from "@mui/material";

import { Spacer, Typography } from "@atoms";
import {
useCreateGovernanceActionForm,

Check failure on line 6 in govtool/frontend/src/components/organisms/VoteContext/VoteContextTerms.tsx

View workflow job for this annotation

GitHub Actions / lint

'useCreateGovernanceActionForm' is defined but never used
useScreenDimension,
useTranslation,
useVoteContextForm,
} from "@hooks";
import { BgCard, ControlledField, VoteContextWrapper } from "@organisms";

Check failure on line 11 in govtool/frontend/src/components/organisms/VoteContext/VoteContextTerms.tsx

View workflow job for this annotation

GitHub Actions / lint

'BgCard' is defined but never used
import { openInNewTab } from "@utils";

type StoreDataInfoProps = {
setStep: Dispatch<SetStateAction<number>>;
};

export const VoteContextTerms = ({ setStep }: StoreDataInfoProps) => {
const { t } = useTranslation();
const { control, errors, watch } = useVoteContextForm();
const { isMobile } = useScreenDimension();

// TODO: change link when available
const openLink = () => openInNewTab("https://docs.sanchogov.tools");

const isContinueDisabled = !watch("terms");

const onClickContinue = () => setStep(6);

Check failure on line 28 in govtool/frontend/src/components/organisms/VoteContext/VoteContextTerms.tsx

View workflow job for this annotation

GitHub Actions / lint

'onClickContinue' is assigned a value but never used

const onClickBack = () => setStep(4);

Check failure on line 30 in govtool/frontend/src/components/organisms/VoteContext/VoteContextTerms.tsx

View workflow job for this annotation

GitHub Actions / lint

'onClickBack' is assigned a value but never used

return (
// <BgCard
// actionButtonLabel={t("continue")}
// isActionButtonDisabled={isContinueDisabled}
// onClickActionButton={onClickContinue}
// onClickBackButton={onClickBack}
// >
<VoteContextWrapper
onContinue={() => setStep(1)}
isContinueDisabled={isContinueDisabled}
>
<Typography sx={{ textAlign: "center" }} variant="headline4">
{t("createGovernanceAction.storeDataTitle")}
</Typography>
<Link
onClick={openLink}
sx={{
cursor: "pointer",
fontSize: 16,
fontWeight: 500,
fontFamily: "Poppins",
my: 4,
textAlign: "center",
textDecoration: "none",
}}
>
{t("createGovernanceAction.storeDataLink")}
</Link>
<ControlledField.Checkbox
{...{ control, errors }}
name="terms"
label={t("createGovernanceAction.storeDataCheckboxLabel")}
layoutStyles={{
display: "flex",
justifyContent: "center",
}}
/>
<Spacer y={isMobile ? 4 : 12.5} />
<Box display="flex" flex={1} />
</VoteContextWrapper>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Dispatch, SetStateAction } from "react";

import { orange } from "@consts";
import { Typography } from "@atoms";
import { VoteContextWrapper } from "@organisms";
import { useTranslation, useVoteContextForm } from "@/hooks";
import { ControlledField } from "..";

type VoteContextTextProps = {
setStep: Dispatch<SetStateAction<number>>;
};

export const VoteContextText = ({ setStep }: VoteContextTextProps) => {
const { t } = useTranslation();

const { control, errors, watch } = useVoteContextForm();

const isContinueDisabled = !watch("text");

const fieldProps = {
key: "text",
layoutStyles: { mb: 3 },
name: "text",
placeholder: "Provide context",
rules: {
required: {
value: true,
message: t("createGovernanceAction.fields.validations.required"),
},
maxLength: {
value: 500,
message: t("createGovernanceAction.fields.validations.maxLength", {
maxLength: 500,
}),
},
},
};

return (
<VoteContextWrapper
onContinue={() => setStep(2)}
isContinueDisabled={isContinueDisabled}
>
<Typography
variant="body1"
sx={{
textTransform: "uppercase",
color: orange.c400,
}}
>
optional
</Typography>
<Typography
variant="title2"
sx={{
lineHeight: "34px",
mb: 1,
}}
>
Provide context about your vote
</Typography>
<Typography variant="body1" sx={{ fontWeight: 400, mb: 2 }}>
Info about how you voting and whats to do now (?)
</Typography>
<ControlledField.TextArea
{...{ control, errors }}
{...fieldProps}
isModifiedLayout
/>
</VoteContextWrapper>
);
};
Loading

0 comments on commit 1af4abd

Please sign in to comment.