Skip to content
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
18 changes: 18 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<ThemeProvider theme={theme}>
<Router history={history}>
Expand Down
45 changes: 45 additions & 0 deletions src/components/form/bounty/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions src/people/widgetViews/postBounty/PostBounty.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,27 @@ export const PostBounty: FC<Props> = 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) {
Expand Down
Loading