Creating a group from create market adds it immediately
This commit is contained in:
parent
c9e782faa7
commit
1da4373335
|
@ -16,10 +16,18 @@ export function CreateGroupButton(props: {
|
||||||
label?: string
|
label?: string
|
||||||
onOpenStateChange?: (isOpen: boolean) => void
|
onOpenStateChange?: (isOpen: boolean) => void
|
||||||
goToGroupOnSubmit?: boolean
|
goToGroupOnSubmit?: boolean
|
||||||
|
addGroupIdParamOnSubmit?: boolean
|
||||||
icon?: JSX.Element
|
icon?: JSX.Element
|
||||||
}) {
|
}) {
|
||||||
const { user, className, label, onOpenStateChange, goToGroupOnSubmit, icon } =
|
const {
|
||||||
props
|
user,
|
||||||
|
className,
|
||||||
|
label,
|
||||||
|
onOpenStateChange,
|
||||||
|
goToGroupOnSubmit,
|
||||||
|
addGroupIdParamOnSubmit,
|
||||||
|
icon,
|
||||||
|
} = props
|
||||||
|
|
||||||
const [name, setName] = useState('')
|
const [name, setName] = useState('')
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
|
@ -53,6 +61,12 @@ export function CreateGroupButton(props: {
|
||||||
console.log(e)
|
console.log(e)
|
||||||
setErrorText(e.message)
|
setErrorText(e.message)
|
||||||
})
|
})
|
||||||
|
else if (addGroupIdParamOnSubmit) {
|
||||||
|
router.replace({
|
||||||
|
pathname: router.pathname,
|
||||||
|
query: { ...router.query, groupId: result.group.id },
|
||||||
|
})
|
||||||
|
}
|
||||||
setIsSubmitting(false)
|
setIsSubmitting(false)
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -131,7 +131,7 @@ export function GroupSelector(props: {
|
||||||
)}
|
)}
|
||||||
<span
|
<span
|
||||||
className={clsx(
|
className={clsx(
|
||||||
'ml-3 mt-1 block flex flex-row justify-between',
|
'ml-3 mt-1 flex flex-row justify-between',
|
||||||
selected && 'font-semibold'
|
selected && 'font-semibold'
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
@ -166,7 +166,7 @@ export function GroupSelector(props: {
|
||||||
'w-full justify-start rounded-none border-0 bg-white pl-2 font-normal text-gray-900 hover:bg-indigo-500 hover:text-white'
|
'w-full justify-start rounded-none border-0 bg-white pl-2 font-normal text-gray-900 hover:bg-indigo-500 hover:text-white'
|
||||||
}
|
}
|
||||||
label={'Create a new Group'}
|
label={'Create a new Group'}
|
||||||
goToGroupOnSubmit={false}
|
addGroupIdParamOnSubmit
|
||||||
icon={
|
icon={
|
||||||
<PlusCircleIcon className="text-primary mr-2 h-5 w-5" />
|
<PlusCircleIcon className="text-primary mr-2 h-5 w-5" />
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,11 @@ export const useWarnUnsavedChanges = (hasUnsavedChanges: boolean) => {
|
||||||
return confirmationMessage
|
return confirmationMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
const beforeRouteHandler = () => {
|
const beforeRouteHandler = (href: string) => {
|
||||||
|
const pathname = href.split('?')[0]
|
||||||
|
// Don't warn if the user is navigating to the same page.
|
||||||
|
if (pathname === location.pathname) return
|
||||||
|
|
||||||
if (!confirm(confirmationMessage)) {
|
if (!confirm(confirmationMessage)) {
|
||||||
Router.events.emit('routeChangeError')
|
Router.events.emit('routeChangeError')
|
||||||
throw 'Abort route change. Please ignore this error.'
|
throw 'Abort route change. Please ignore this error.'
|
||||||
|
@ -21,7 +25,7 @@ export const useWarnUnsavedChanges = (hasUnsavedChanges: boolean) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('beforeunload', warnUnsavedChanges)
|
window.addEventListener('beforeunload', warnUnsavedChanges)
|
||||||
Router.events.on('routeChangeStart', beforeRouteHandler)
|
Router.events.on('routeChangeStart', (href) => beforeRouteHandler(href))
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('beforeunload', warnUnsavedChanges)
|
window.removeEventListener('beforeunload', warnUnsavedChanges)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user