-
Notifications
You must be signed in to change notification settings - Fork 10
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
[#358] [#359] [#151] feat/358-choose-a-governance-action-type #383
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove console.log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or add TODO that it will be removed in favor of submitting governance action to service/csl