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

fix/1389-bug-clearing-name-field-on-edit-drep-form-causes-it-to-reappear-and-adds-extra-link-input #1397

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ const MAX_NUMBER_OF_LINKS = 7;
export const EditDRepForm = ({
onClickCancel,
setStep,
loadUserData,
setLoadUserData,
}: {
onClickCancel: () => void;
setStep: Dispatch<SetStateAction<number>>;
loadUserData: boolean;
setLoadUserData: Dispatch<SetStateAction<boolean>>;
}) => {
const { state } = useLocation();
const { t } = useTranslation();
const { isMobile } = useScreenDimension();
const { dRepID } = useCardano();
const { control, errors, isError, register, watch, reset, getValues } =
const { control, errors, isError, register, watch, reset } =
useEditDRepInfoForm();
const {
append,
Expand All @@ -47,7 +51,10 @@ export const EditDRepForm = ({
{ enabled: !state },
);

const onClickContinue = () => setStep(2);
const onClickContinue = () => {
setStep(2);
setLoadUserData(false);
};

const addLink = useCallback(() => append({ uri: "" }), [append]);

Expand All @@ -56,25 +63,28 @@ export const EditDRepForm = ({
const isContinueButtonDisabled = !watch("dRepName") || isError;

useEffect(() => {
if (!getValues().dRepName)
if (loadUserData) {
reset(
state
? {
...state,
references: state.references.map((uri: string) => ({
uri,
})),
references: state.references.length
? state.references.map((uri: string) => ({
uri,
}))
: [{ uri: "" }],
}
: {
...yourselfDRepList?.[0],
references: yourselfDRepList?.[0].references.map(
(uri: string) => ({
uri,
}),
),
references: yourselfDRepList?.[0].references.length
? yourselfDRepList?.[0].references.map((uri: string) => ({
uri,
}))
: [{ uri: "" }],
},
);
}, [yourselfDRepList]);
}
}, [yourselfDRepList?.[0], loadUserData]);

const renderLinks = useCallback(
() =>
Expand Down
1 change: 1 addition & 0 deletions govtool/frontend/src/hooks/forms/useEditDRepInfoForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const useEditDRepInfoForm = (

// Navigation
const backToForm = useCallback(() => {
window.scrollTo(0, 0);
setStep?.(1);
closeModal();
}, [setStep]);
Expand Down
3 changes: 3 additions & 0 deletions govtool/frontend/src/pages/EditDRepMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { checkIsWalletConnected } from "@utils";

export const EditDRepMetadata = () => {
const [step, setStep] = useState<number>(1);
const [loadUserData, setLoadUserData] = useState(true);
const { isMobile } = useScreenDimension();
const navigate = useNavigate();
const { t } = useTranslation();
Expand Down Expand Up @@ -95,6 +96,8 @@ export const EditDRepMetadata = () => {
<EditDRepForm
onClickCancel={onClickBackToDashboard}
setStep={setStep}
loadUserData={loadUserData}
setLoadUserData={setLoadUserData}
/>
)}
{step === 2 && <EditDRepStoreDataInfo setStep={setStep} />}
Expand Down
Loading