Skip to content

Commit 784cff4

Browse files
authored
Merge pull request #1558 from fayekelmith/feat/hive-integration
feat: accept prefilled data for bounty creation
2 parents 79db848 + 6add782 commit 784cff4

3 files changed

Lines changed: 79 additions & 2 deletions

File tree

src/App.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ function App() {
8787
setPosthog();
8888
}, [setPosthog]);
8989

90+
useEffect(() => {
91+
const urlParams = new URLSearchParams(window.location.search);
92+
const prefillParam = urlParams.get('prefill');
93+
const action = urlParams.get('action');
94+
95+
if (action === 'create' && prefillParam && !uiStore.meInfo) {
96+
sessionStorage.setItem('sphinxBountyPrefill', prefillParam);
97+
}
98+
99+
if (uiStore.meInfo) {
100+
const storedPrefill = sessionStorage.getItem('sphinxBountyPrefill');
101+
if (storedPrefill && window.location.pathname === '/bounties') {
102+
sessionStorage.removeItem('sphinxBountyPrefill');
103+
history.push(`/bounties?action=create&prefill=${storedPrefill}`);
104+
}
105+
}
106+
}, [uiStore.meInfo]);
107+
90108
return (
91109
<ThemeProvider theme={theme}>
92110
<Router history={history}>

src/components/form/bounty/index.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,50 @@ function Form(props: FormProps) {
104104
return urlParts[urlParts.length - 1];
105105
}, []);
106106

107+
useEffect(() => {
108+
const urlParams = new URLSearchParams(window.location.search);
109+
const prefillParam = urlParams.get('prefill');
110+
const action = urlParams.get('action');
111+
112+
if (action === 'create' && prefillParam) {
113+
try {
114+
const decoded = JSON.parse(atob(prefillParam));
115+
116+
const mapHoursToSession = (hours: number): string => {
117+
if (hours <= 1) return '1 hour';
118+
if (hours <= 3) return '3 hours';
119+
if (hours <= 8) return '8 hours';
120+
if (hours <= 24) return '24 hours';
121+
if (hours <= 48) return '48 hours';
122+
return '72 hours';
123+
};
124+
125+
const mappedData: any = {
126+
one_sentence_summary: decoded.title || '',
127+
description: decoded.description || '',
128+
wanted_type: 'Web development'
129+
};
130+
131+
if (decoded.estimatedHours) {
132+
mappedData.estimated_session_length = mapHoursToSession(decoded.estimatedHours);
133+
}
134+
135+
if (decoded.repositoryUrl) {
136+
mappedData.ticket_url = decoded.repositoryUrl;
137+
}
138+
139+
setDynamicSchemaName('freelance_job_request');
140+
setDynamicSchema(dynamicSchemasByType['freelance_job_request']);
141+
setDynamicInitialValues(mappedData);
142+
setStepTracker(2);
143+
144+
window.history.replaceState({}, '', '/bounties?action=create');
145+
} catch (error) {
146+
console.error('Failed to parse prefill data:', error);
147+
}
148+
}
149+
}, []);
150+
107151
useEffect(() => {
108152
async function fetchWorkspaces() {
109153
if (ui.meInfo?.id) {
@@ -346,6 +390,7 @@ function Form(props: FormProps) {
346390
onSubmit={props.onSubmit}
347391
innerRef={props.formRef}
348392
validationSchema={validator(schema)}
393+
enableReinitialize={true}
349394
>
350395
{({ setFieldTouched, handleSubmit, values, setFieldValue, errors, initialValues }: any) => {
351396
const isDescriptionValid = values.ticket_url

src/people/widgetViews/postBounty/PostBounty.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,27 @@ export const PostBounty: FC<Props> = observer(
5858
const [isOpenStartUpModel, setIsOpenStartupModal] = useState(false);
5959

6060
const isMobile = useIsMobile();
61-
const showSignIn = () => {
61+
const showSignIn = React.useCallback(() => {
6262
if (isMobile) {
6363
ui.setShowSignIn(true);
6464
return;
6565
}
6666
setIsOpenStartupModal(true);
67-
};
67+
}, [isMobile, ui]);
68+
69+
React.useEffect(() => {
70+
const urlParams = new URLSearchParams(window.location.search);
71+
const prefillParam = urlParams.get('prefill');
72+
const action = urlParams.get('action');
73+
74+
if (action === 'create' && prefillParam) {
75+
if (ui.meInfo && ui.meInfo?.owner_alias) {
76+
setIsOpenPostModal(true);
77+
} else {
78+
showSignIn();
79+
}
80+
}
81+
}, [ui.meInfo, showSignIn]);
6882

6983
const clickHandler = () => {
7084
if (ui.meInfo && ui.meInfo?.owner_alias) {

0 commit comments

Comments
 (0)