From 6add782d711801714e0ef22c78c197806c80a7be Mon Sep 17 00:00:00 2001 From: kelmith Date: Mon, 20 Oct 2025 20:26:57 +0530 Subject: [PATCH] accept prefilled data for bounty creation --- src/App.tsx | 18 ++++++++ src/components/form/bounty/index.tsx | 45 +++++++++++++++++++ .../widgetViews/postBounty/PostBounty.tsx | 18 +++++++- 3 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 19659de16..5c6b95183 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -87,6 +87,24 @@ function App() { setPosthog(); }, [setPosthog]); + useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + const prefillParam = urlParams.get('prefill'); + const action = urlParams.get('action'); + + if (action === 'create' && prefillParam && !uiStore.meInfo) { + sessionStorage.setItem('sphinxBountyPrefill', prefillParam); + } + + if (uiStore.meInfo) { + const storedPrefill = sessionStorage.getItem('sphinxBountyPrefill'); + if (storedPrefill && window.location.pathname === '/bounties') { + sessionStorage.removeItem('sphinxBountyPrefill'); + history.push(`/bounties?action=create&prefill=${storedPrefill}`); + } + } + }, [uiStore.meInfo]); + return ( diff --git a/src/components/form/bounty/index.tsx b/src/components/form/bounty/index.tsx index 0af268cfa..f0e04e100 100644 --- a/src/components/form/bounty/index.tsx +++ b/src/components/form/bounty/index.tsx @@ -104,6 +104,50 @@ function Form(props: FormProps) { return urlParts[urlParts.length - 1]; }, []); + useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + const prefillParam = urlParams.get('prefill'); + const action = urlParams.get('action'); + + if (action === 'create' && prefillParam) { + try { + const decoded = JSON.parse(atob(prefillParam)); + + const mapHoursToSession = (hours: number): string => { + if (hours <= 1) return '1 hour'; + if (hours <= 3) return '3 hours'; + if (hours <= 8) return '8 hours'; + if (hours <= 24) return '24 hours'; + if (hours <= 48) return '48 hours'; + return '72 hours'; + }; + + const mappedData: any = { + one_sentence_summary: decoded.title || '', + description: decoded.description || '', + wanted_type: 'Web development' + }; + + if (decoded.estimatedHours) { + mappedData.estimated_session_length = mapHoursToSession(decoded.estimatedHours); + } + + if (decoded.repositoryUrl) { + mappedData.ticket_url = decoded.repositoryUrl; + } + + setDynamicSchemaName('freelance_job_request'); + setDynamicSchema(dynamicSchemasByType['freelance_job_request']); + setDynamicInitialValues(mappedData); + setStepTracker(2); + + window.history.replaceState({}, '', '/bounties?action=create'); + } catch (error) { + console.error('Failed to parse prefill data:', error); + } + } + }, []); + useEffect(() => { async function fetchWorkspaces() { if (ui.meInfo?.id) { @@ -346,6 +390,7 @@ function Form(props: FormProps) { onSubmit={props.onSubmit} innerRef={props.formRef} validationSchema={validator(schema)} + enableReinitialize={true} > {({ setFieldTouched, handleSubmit, values, setFieldValue, errors, initialValues }: any) => { const isDescriptionValid = values.ticket_url diff --git a/src/people/widgetViews/postBounty/PostBounty.tsx b/src/people/widgetViews/postBounty/PostBounty.tsx index 439c5e1fe..a9bb74baf 100644 --- a/src/people/widgetViews/postBounty/PostBounty.tsx +++ b/src/people/widgetViews/postBounty/PostBounty.tsx @@ -58,13 +58,27 @@ export const PostBounty: FC = observer( const [isOpenStartUpModel, setIsOpenStartupModal] = useState(false); const isMobile = useIsMobile(); - const showSignIn = () => { + const showSignIn = React.useCallback(() => { if (isMobile) { ui.setShowSignIn(true); return; } setIsOpenStartupModal(true); - }; + }, [isMobile, ui]); + + React.useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + const prefillParam = urlParams.get('prefill'); + const action = urlParams.get('action'); + + if (action === 'create' && prefillParam) { + if (ui.meInfo && ui.meInfo?.owner_alias) { + setIsOpenPostModal(true); + } else { + showSignIn(); + } + } + }, [ui.meInfo, showSignIn]); const clickHandler = () => { if (ui.meInfo && ui.meInfo?.owner_alias) {