Skip to content

Commit

Permalink
update: after edit return to previous page (#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobi-bams authored Nov 16, 2023
1 parent cb14558 commit 854faba
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
9 changes: 6 additions & 3 deletions frontend/app/src/components/form/bounty/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,16 @@ function Form(props: FormProps) {
<div style={{ display: 'flex', alignItems: 'center' }}>
<Button
disabled={disableFormButtons || props.loading}
onClick={() => {
onClick={async () => {
if (dynamicSchemaName) {
// inject type in body
setFieldValue('type', dynamicSchemaName);
}
handleSubmit();
history.push('/bounties');
await handleSubmit(true);
setTimeout(() => {
props.setLoading && props.setLoading(false);
props.onEditSuccess && props.onEditSuccess();
}, 500);
}}
loading={props.loading}
style={{ ...buttonStyle, width: '140px' }}
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/src/components/form/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ export interface FormProps {
loading?: boolean;
delete?: () => void;
submitText?: string;
onEditSuccess?: () => void;
setLoading?: (value: boolean) => void;
}
2 changes: 1 addition & 1 deletion frontend/app/src/pages/tickets/TicketModalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const TicketModalPage = observer(({ setConnectPerson }: Props) => {

useEffect(() => {
getBounty();
}, [getBounty]);
}, [getBounty, removeNextAndPrev]);

const goBack = async () => {
setVisible(false);
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/src/people/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface FocusViewProps {
setIsExtraStyle?: any;
bounty?: PersonBounty[];
setRemoveNextAndPrev?: (boolean) => void;
setAfterEdit?: (boolean) => void;
}

export interface PeopleMobileeHeaderProps {
Expand Down Expand Up @@ -239,7 +240,7 @@ export interface WantedSummaryProps {
show: boolean;
setIsModalSideButton: (any) => void;
setIsExtraStyle: (any) => void;
formSubmit: (any, close?: boolean) => void;
formSubmit: (any, notEdit?: boolean) => void;
title: string;
org_uuid?: string;
id?: number;
Expand Down
21 changes: 15 additions & 6 deletions frontend/app/src/people/main/FocusView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { FocusViewProps } from 'people/interfaces';
import { EuiGlobalToastList } from '@elastic/eui';
import { Organization } from 'store/main';
import { Box } from '@mui/system';
import history from 'config/history';
import { useStores } from '../../store';
import Form from '../../components/form/bounty';
import {
Expand Down Expand Up @@ -41,7 +40,8 @@ function FocusedView(props: FocusViewProps) {
newDesign,
setIsModalSideButton,
bounty,
setRemoveNextAndPrev
setRemoveNextAndPrev,
setAfterEdit
} = props;
const { ui, main } = useStores();

Expand Down Expand Up @@ -200,9 +200,8 @@ function FocusedView(props: FocusViewProps) {
}

// eslint-disable-next-line @typescript-eslint/no-inferrable-types
async function submitForm(body: any, shouldCloseModal: boolean = true) {
async function submitForm(body: any, notEdit?: boolean) {
let newBody = cloneDeep(body);

try {
newBody = await preSubmitFunctions(newBody);
} catch (e) {
Expand Down Expand Up @@ -238,15 +237,16 @@ function FocusedView(props: FocusViewProps) {
// Refresh the tickets page if a user eidts from the tickets tab
if (window.location.href.includes('wanted')) {
await main.getPersonCreatedBounties({}, info.pubkey);
history.goBack();
}
} catch (e) {
console.log('e', e);
}

if (props?.onSuccess) props.onSuccess();

setLoading(false);
if (notEdit === true) {
setLoading(false);
}
if (ui?.meInfo?.hasOwnProperty('url') && !isNotHttps(ui?.meInfo?.url) && props?.ReCallBounties)
props?.ReCallBounties();
}
Expand Down Expand Up @@ -320,6 +320,13 @@ function FocusedView(props: FocusViewProps) {
setRemoveNextAndPrev && setRemoveNextAndPrev(true);
}

function handleEditFinish() {
setEditable(true);
setEditMode(false);
setRemoveNextAndPrev && setRemoveNextAndPrev(false);
setAfterEdit && setAfterEdit(true);
}

function handleFormClose() {
if (skipEditLayer && goBack) goBack();
else {
Expand Down Expand Up @@ -365,6 +372,8 @@ function FocusedView(props: FocusViewProps) {
}
: {}
}
onEditSuccess={handleEditFinish}
setLoading={setLoading}
/>
)}
</B>
Expand Down
26 changes: 20 additions & 6 deletions frontend/app/src/people/main/bountyModal/BountyModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Modal } from 'components/common';
import { useIsMobile, usePerson } from 'hooks';
import { widgetConfigs } from 'people/utils/Constants';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useCallback } from 'react';
import { useHistory, useParams } from 'react-router-dom';
import { useStores } from 'store';
import { BountyModalProps } from 'people/interfaces';
Expand All @@ -20,6 +20,7 @@ export const BountyModal = ({ basePath, fromPage, bountyOwner }: BountyModalProp
const { ui, main } = useStores();
const { person } = usePerson(ui.selectedPerson);
const [bounty, setBounty] = useState<PersonBounty[]>([]);
const [afterEdit, setAfterEdit] = useState(false);

const personToDisplay = fromPage === 'usertickets' ? bountyOwner : person;

Expand All @@ -33,20 +34,31 @@ export const BountyModal = ({ basePath, fromPage, bountyOwner }: BountyModalProp
});
};

useEffect(() => {
async function getBounty() {
const getBounty = useCallback(
async (afterEdit?: boolean) => {
/** check for the bounty length, else the request
* will be made continously which will lead to an
* infinite loop and crash the app
*/
if (wantedId && !bounty.length) {
if ((wantedId && !bounty.length) || afterEdit) {
const bounty = await main.getBountyById(Number(wantedId));
setBounty(bounty);
}
}
},
[bounty, main, wantedId]
);

useEffect(() => {
getBounty();
}, [bounty, main, wantedId]);
}, [getBounty]);

useEffect(() => {
if (afterEdit) {
getBounty(afterEdit);
setAfterEdit(false);
}
}, [afterEdit, getBounty]);

const isMobile = useIsMobile();

if (isMobile) {
Expand All @@ -59,6 +71,7 @@ export const BountyModal = ({ basePath, fromPage, bountyOwner }: BountyModalProp
selectedIndex={Number(wantedIndex)}
config={config}
goBack={onGoBack}
setAfterEdit={setAfterEdit}
/>
</Modal>
);
Expand Down Expand Up @@ -99,6 +112,7 @@ export const BountyModal = ({ basePath, fromPage, bountyOwner }: BountyModalProp
onGoBack();
}}
fromBountyPage={true}
setAfterEdit={setAfterEdit}
/>
</Modal>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function WantedSummary(props: WantedSummaryProps) {
created: created
};

formSubmit && formSubmit(newValue);
formSubmit && formSubmit(newValue, true);
},
[
coding_languages,
Expand Down Expand Up @@ -192,7 +192,7 @@ function WantedSummary(props: WantedSummaryProps) {
type: type,
created: created
};
formSubmit && formSubmit(newValue, false);
formSubmit && formSubmit(newValue, true);
}, [
coding_languages,
created,
Expand Down

0 comments on commit 854faba

Please sign in to comment.