-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ion modals
- Loading branch information
Showing
17 changed files
with
308 additions
and
12 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
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
26 changes: 26 additions & 0 deletions
26
govtool/frontend/src/components/molecules/BackToButton.tsx
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,26 @@ | ||
import { Box } from "@mui/material"; | ||
import ArrowBackIosIcon from "@mui/icons-material/ArrowBackIos"; | ||
|
||
import { Typography } from "@atoms"; | ||
|
||
import { BackToLinkProps } from "./types"; | ||
|
||
export const BackToButton = ({ label, onClick, sx }: BackToLinkProps) => { | ||
return ( | ||
<Box | ||
data-testid="back-to-dashboard-link" | ||
sx={{ | ||
alignItems: "center", | ||
cursor: "pointer", | ||
display: "flex", | ||
...sx, | ||
}} | ||
onClick={onClick} | ||
> | ||
<ArrowBackIosIcon color="primary" sx={{ fontSize: 14 }} /> | ||
<Typography color="primary" fontWeight={400} variant="body2"> | ||
{label} | ||
</Typography> | ||
</Box> | ||
); | ||
}; |
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,7 @@ | ||
import { SxProps } from "@mui/material"; | ||
|
||
export type BackToLinkProps = { | ||
label: string; | ||
onClick: () => void; | ||
sx?: SxProps; | ||
}; |
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
70 changes: 70 additions & 0 deletions
70
govtool/frontend/src/components/organisms/ChooseGovernanceActionType.tsx
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,70 @@ | ||
import { Dispatch, SetStateAction } from "react"; | ||
|
||
import { ActionRadio, Spacer, Typography } from "@atoms"; | ||
import { GOVERNANCE_ACTION_TYPES } from "@consts"; | ||
import { | ||
useCreateGovernanceActionForm, | ||
useScreenDimension, | ||
useTranslation, | ||
} from "@hooks"; | ||
|
||
import { BgCard } from "./BgCard"; | ||
|
||
type ChooseGovernanceActionTypeProps = { | ||
onClickCancel: () => void; | ||
setStep: Dispatch<SetStateAction<number>>; | ||
}; | ||
|
||
export const ChooseGovernanceActionType = ({ | ||
onClickCancel, | ||
setStep, | ||
}: ChooseGovernanceActionTypeProps) => { | ||
const { t } = useTranslation(); | ||
const { isMobile } = useScreenDimension(); | ||
const { getValues, setValue, watch } = useCreateGovernanceActionForm(); | ||
|
||
const isContinueButtonDisabled = !watch("type"); | ||
|
||
const onClickContinue = () => { | ||
setStep(2); | ||
}; | ||
|
||
// TODO: Add tooltips when they will be available | ||
const renderGovernanceActionTypes = () => { | ||
return GOVERNANCE_ACTION_TYPES.map((type, index) => { | ||
const isChecked = getValues("type") === type; | ||
return ( | ||
<> | ||
<ActionRadio | ||
isChecked={isChecked} | ||
onChange={onChangeType} | ||
title={type} | ||
value={type} | ||
/> | ||
{index + 1 < GOVERNANCE_ACTION_TYPES.length ? <Spacer y={2} /> : null} | ||
</> | ||
); | ||
}); | ||
}; | ||
|
||
const onChangeType = (value: string) => { | ||
setValue("type", value); | ||
}; | ||
|
||
return ( | ||
<BgCard | ||
actionButtonLabel={t("continue")} | ||
backButtonLabel={t("cancel")} | ||
isActionButtonDisabled={isContinueButtonDisabled} | ||
onClickActionButton={onClickContinue} | ||
onClickBackButton={onClickCancel} | ||
> | ||
<Typography sx={{ textAlign: "center" }} variant="headline4"> | ||
{t("createGovernanceAction.chooseGATypeTitle")} | ||
</Typography> | ||
<Spacer y={isMobile ? 4.25 : 7.5} /> | ||
{renderGovernanceActionTypes()} | ||
<Spacer y={isMobile ? 6 : 7.5} /> | ||
</BgCard> | ||
); | ||
}; |
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 @@ | ||
export const GOVERNANCE_ACTION_TYPES = ["Info", "Treasury"]; |
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
45 changes: 45 additions & 0 deletions
45
govtool/frontend/src/hooks/forms/useCreateGovernanceActionForm.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,45 @@ | ||
import { useCallback, useState } from "react"; | ||
import { useFormContext } from "react-hook-form"; | ||
|
||
type createGovernanceActionValues = { | ||
type: string; | ||
}; | ||
|
||
export const defaulCreateGovernanceActionValues: createGovernanceActionValues = | ||
{ | ||
type: "", | ||
}; | ||
|
||
export const useCreateGovernanceActionForm = () => { | ||
const [isLoading, setIsLoading] = useState<boolean>(false); | ||
|
||
const { | ||
control, | ||
formState: { errors, isValid }, | ||
getValues, | ||
handleSubmit, | ||
setValue, | ||
watch, | ||
} = useFormContext<createGovernanceActionValues>(); | ||
|
||
const onSubmit = useCallback(async (values: createGovernanceActionValues) => { | ||
setIsLoading(true); | ||
console.log(values); | ||
try { | ||
} catch (e: any) { | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
}, []); | ||
|
||
return { | ||
control, | ||
errors, | ||
getValues, | ||
isLoading, | ||
isValid, | ||
setValue, | ||
submitForm: handleSubmit(onSubmit), | ||
watch, | ||
}; | ||
}; |
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,85 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { FormProvider, useForm } from "react-hook-form"; | ||
import { Box } from "@mui/material"; | ||
|
||
import { Background } from "@atoms"; | ||
import { PATHS } from "@consts"; | ||
import { useModal } from "@context"; | ||
import { | ||
defaulCreateGovernanceActionValues, | ||
useScreenDimension, | ||
useTranslation, | ||
} from "@hooks"; | ||
import { BackToButton } from "@molecules"; | ||
import { | ||
ChooseGovernanceActionType, | ||
DashboardTopNav, | ||
Footer, | ||
} from "@organisms"; | ||
import { checkIsWalletConnected } from "@utils"; | ||
|
||
export const CreateGovernanceAction = () => { | ||
const navigate = useNavigate(); | ||
const { t } = useTranslation(); | ||
const { isMobile } = useScreenDimension(); | ||
const { closeModal, openModal } = useModal(); | ||
const [step, setStep] = useState(1); | ||
|
||
const methods = useForm({ | ||
mode: "onBlur", | ||
defaultValues: defaulCreateGovernanceActionValues, | ||
}); | ||
|
||
useEffect(() => { | ||
if (checkIsWalletConnected()) { | ||
navigate(PATHS.home); | ||
} | ||
}, []); | ||
|
||
const onClickBackToDashboard = () => | ||
openModal({ | ||
type: "statusModal", | ||
state: { | ||
status: "warning", | ||
message: t("modals.createGovernanceAction.cancelModalDescription"), | ||
buttonText: t("modals.common.goToDashboard"), | ||
title: t("modals.createGovernanceAction.cancelModalTitle"), | ||
dataTestId: "cancel-governance-action-creation-modal", | ||
onSubmit: backToDashboard, | ||
}, | ||
}); | ||
|
||
const backToDashboard = () => { | ||
navigate(PATHS.dashboard); | ||
closeModal(); | ||
}; | ||
|
||
return ( | ||
<Background isReverted> | ||
<Box | ||
sx={{ display: "flex", flexDirection: "column", minHeight: "100vh" }} | ||
> | ||
<DashboardTopNav title={t("createGovernanceAction.title")} /> | ||
<BackToButton | ||
label={t("backToDashboard")} | ||
onClick={onClickBackToDashboard} | ||
sx={{ | ||
mb: isMobile ? 0 : 1.5, | ||
ml: isMobile ? 2 : 5, | ||
mt: isMobile ? 3 : 1.5, | ||
}} | ||
/> | ||
<FormProvider {...methods}> | ||
{step === 1 && ( | ||
<ChooseGovernanceActionType | ||
onClickCancel={onClickBackToDashboard} | ||
setStep={setStep} | ||
/> | ||
)} | ||
</FormProvider> | ||
{isMobile && <Footer />} | ||
</Box> | ||
</Background> | ||
); | ||
}; |
Oops, something went wrong.