Commit c247a3db authored by Stefan Probst's avatar Stefan Probst
Browse files

fix: adjust submit button for moderators

parent 2a1c4ee9
import { useRouter } from 'next/router'
import { useQueryClient } from 'react-query'
import type { DatasetCore, DatasetDto } from '@/api/sshoc'
import { useCreateDataset } from '@/api/sshoc'
import {
DatasetCore,
DatasetDto,
useCreateDataset,
useGetLoggedInUser,
} from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ActorsFormSection } from '@/components/item/ActorsFormSection/ActorsFormSection'
import { DateFormSection } from '@/components/item/DateFormSection/DateFormSection'
......@@ -39,10 +43,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const toast = useToast()
const router = useRouter()
const auth = useAuth()
const user = useGetLoggedInUser()
const isAllowedToPublish =
user.data?.role !== undefined
? ['administrator', 'moderator'].includes(user.data.role)
: false
const queryClient = useQueryClient()
const create = useItemMutation({
onSuccess(data: DatasetDto) {
toast.success(`Successfully submitted ${categoryLabel}.`)
toast.success(
`Successfully ${
isAllowedToPublish ? 'published' : 'submitted'
} ${categoryLabel}.`,
)
queryClient.invalidateQueries({
queryKey: ['itemSearch'],
......@@ -69,7 +82,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
}
},
onError() {
toast.error(`Failed to submit ${categoryLabel}.`)
toast.error(
`Failed to ${
isAllowedToPublish ? 'publish' : 'submit'
} ${categoryLabel}.`,
)
},
})
......@@ -151,7 +168,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
pristine || invalid || submitting || create.isLoading
}
>
Submit
{isAllowedToPublish ? 'Publish' : 'Submit'}
</Button>
</div>
</form>
......
import { useRouter } from 'next/router'
import { useQueryClient } from 'react-query'
import type { DatasetCore, DatasetDto } from '@/api/sshoc'
import { useUpdateDataset } from '@/api/sshoc'
import {
DatasetCore,
DatasetDto,
useGetLoggedInUser,
useUpdateDataset,
} from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ActorsFormSection } from '@/components/item/ActorsFormSection/ActorsFormSection'
import { DateFormSection } from '@/components/item/DateFormSection/DateFormSection'
......@@ -41,10 +45,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const toast = useToast()
const router = useRouter()
const auth = useAuth()
const user = useGetLoggedInUser()
const isAllowedToPublish =
user.data?.role !== undefined
? ['administrator', 'moderator'].includes(user.data.role)
: false
const queryClient = useQueryClient()
const create = useItemMutation({
onSuccess(data: DatasetDto) {
toast.success(`Successfully submitted ${categoryLabel}.`)
toast.success(
`Successfully ${
isAllowedToPublish ? 'published' : 'submitted'
} ${categoryLabel}.`,
)
queryClient.invalidateQueries({
queryKey: ['itemSearch'],
......@@ -71,7 +84,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
}
},
onError() {
toast.error(`Failed to submit ${categoryLabel}.`)
toast.error(
`Failed to ${
isAllowedToPublish ? 'publish' : 'submit'
} ${categoryLabel}.`,
)
},
})
......@@ -153,7 +170,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
pristine || invalid || submitting || create.isLoading
}
>
Submit
{isAllowedToPublish ? 'Publish' : 'Submit'}
</Button>
</div>
</form>
......
import { useRouter } from 'next/router'
import { useQueryClient } from 'react-query'
import type { PublicationCore, PublicationDto } from '@/api/sshoc'
import { useCreatePublication } from '@/api/sshoc'
import {
PublicationCore,
PublicationDto,
useCreatePublication,
useGetLoggedInUser,
} from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ActorsFormSection } from '@/components/item/ActorsFormSection/ActorsFormSection'
import { DateFormSection } from '@/components/item/DateFormSection/DateFormSection'
......@@ -39,10 +43,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const toast = useToast()
const router = useRouter()
const auth = useAuth()
const user = useGetLoggedInUser()
const isAllowedToPublish =
user.data?.role !== undefined
? ['administrator', 'moderator'].includes(user.data.role)
: false
const queryClient = useQueryClient()
const create = useItemMutation({
onSuccess(data: PublicationDto) {
toast.success(`Successfully submitted ${categoryLabel}.`)
toast.success(
`Successfully ${
isAllowedToPublish ? 'published' : 'submitted'
} ${categoryLabel}.`,
)
queryClient.invalidateQueries({
queryKey: ['itemSearch'],
......@@ -69,7 +82,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
}
},
onError() {
toast.error(`Failed to submit ${categoryLabel}.`)
toast.error(
`Failed to ${
isAllowedToPublish ? 'publish' : 'submit'
} ${categoryLabel}.`,
)
},
})
......@@ -150,7 +167,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
pristine || invalid || submitting || create.isLoading
}
>
Submit
{isAllowedToPublish ? 'Publish' : 'Submit'}
</Button>
</div>
</form>
......
import { useRouter } from 'next/router'
import { useQueryClient } from 'react-query'
import type { PublicationCore, PublicationDto } from '@/api/sshoc'
import { useUpdatePublication } from '@/api/sshoc'
import {
PublicationCore,
PublicationDto,
useGetLoggedInUser,
useUpdatePublication,
} from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ActorsFormSection } from '@/components/item/ActorsFormSection/ActorsFormSection'
import { DateFormSection } from '@/components/item/DateFormSection/DateFormSection'
......@@ -41,10 +45,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const toast = useToast()
const router = useRouter()
const auth = useAuth()
const user = useGetLoggedInUser()
const isAllowedToPublish =
user.data?.role !== undefined
? ['administrator', 'moderator'].includes(user.data.role)
: false
const queryClient = useQueryClient()
const create = useItemMutation({
onSuccess(data: PublicationDto) {
toast.success(`Successfully submitted ${categoryLabel}.`)
toast.success(
`Successfully ${
isAllowedToPublish ? 'published' : 'submitted'
} ${categoryLabel}.`,
)
queryClient.invalidateQueries({
queryKey: ['itemSearch'],
......@@ -71,7 +84,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
}
},
onError() {
toast.error(`Failed to submit ${categoryLabel}.`)
toast.error(
`Failed to ${
isAllowedToPublish ? 'publish' : 'submit'
} ${categoryLabel}.`,
)
},
})
......@@ -153,7 +170,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
pristine || invalid || submitting || create.isLoading
}
>
Submit
{isAllowedToPublish ? 'Publish' : 'Submit'}
</Button>
</div>
</form>
......
import { useRouter } from 'next/router'
import { useQueryClient } from 'react-query'
import type { ToolCore, ToolDto } from '@/api/sshoc'
import { useCreateTool } from '@/api/sshoc'
import {
ToolCore,
ToolDto,
useCreateTool,
useGetLoggedInUser,
} from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ActorsFormSection } from '@/components/item/ActorsFormSection/ActorsFormSection'
import { MainFormSection } from '@/components/item/MainFormSection/MainFormSection'
......@@ -37,10 +41,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const toast = useToast()
const router = useRouter()
const auth = useAuth()
const user = useGetLoggedInUser()
const isAllowedToPublish =
user.data?.role !== undefined
? ['administrator', 'moderator'].includes(user.data.role)
: false
const queryClient = useQueryClient()
const create = useItemMutation({
onSuccess(data: ToolDto) {
toast.success(`Successfully submitted ${categoryLabel}.`)
toast.success(
`Successfully ${
isAllowedToPublish ? 'published' : 'submitted'
} ${categoryLabel}.`,
)
queryClient.invalidateQueries({
queryKey: ['itemSearch'],
......@@ -67,7 +80,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
}
},
onError() {
toast.error(`Failed to submit ${categoryLabel}.`)
toast.error(
`Failed to ${
isAllowedToPublish ? 'publish' : 'submit'
} ${categoryLabel}.`,
)
},
})
......@@ -146,7 +163,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
pristine || invalid || submitting || create.isLoading
}
>
Submit
{isAllowedToPublish ? 'Publish' : 'Submit'}
</Button>
</div>
</form>
......
import { useRouter } from 'next/router'
import { useQueryClient } from 'react-query'
import type { ToolCore, ToolDto } from '@/api/sshoc'
import { useUpdateTool } from '@/api/sshoc'
import {
ToolCore,
ToolDto,
useGetLoggedInUser,
useUpdateTool,
} from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ActorsFormSection } from '@/components/item/ActorsFormSection/ActorsFormSection'
import { MainFormSection } from '@/components/item/MainFormSection/MainFormSection'
......@@ -39,10 +43,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const toast = useToast()
const router = useRouter()
const auth = useAuth()
const user = useGetLoggedInUser()
const isAllowedToPublish =
user.data?.role !== undefined
? ['administrator', 'moderator'].includes(user.data.role)
: false
const queryClient = useQueryClient()
const create = useItemMutation({
onSuccess(data: ToolDto) {
toast.success(`Successfully submitted ${categoryLabel}.`)
toast.success(
`Successfully ${
isAllowedToPublish ? 'published' : 'submitted'
} ${categoryLabel}.`,
)
queryClient.invalidateQueries({
queryKey: ['itemSearch'],
......@@ -69,7 +82,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
}
},
onError() {
toast.error(`Failed to submit ${categoryLabel}.`)
toast.error(
`Failed to ${
isAllowedToPublish ? 'publish' : 'submit'
} ${categoryLabel}.`,
)
},
})
......@@ -149,7 +166,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
pristine || invalid || submitting || create.isLoading
}
>
Submit
{isAllowedToPublish ? 'Publish' : 'Submit'}
</Button>
</div>
</form>
......
import { useRouter } from 'next/router'
import { useQueryClient } from 'react-query'
import type { TrainingMaterialCore, TrainingMaterialDto } from '@/api/sshoc'
import { useCreateTrainingMaterial } from '@/api/sshoc'
import {
TrainingMaterialCore,
TrainingMaterialDto,
useCreateTrainingMaterial,
useGetLoggedInUser,
} from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ActorsFormSection } from '@/components/item/ActorsFormSection/ActorsFormSection'
import { MainFormSection } from '@/components/item/MainFormSection/MainFormSection'
......@@ -37,10 +41,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const toast = useToast()
const router = useRouter()
const auth = useAuth()
const user = useGetLoggedInUser()
const isAllowedToPublish =
user.data?.role !== undefined
? ['administrator', 'moderator'].includes(user.data.role)
: false
const queryClient = useQueryClient()
const create = useItemMutation({
onSuccess(data: TrainingMaterialDto) {
toast.success(`Successfully submitted ${categoryLabel}.`)
toast.success(
`Successfully ${
isAllowedToPublish ? 'published' : 'submitted'
} ${categoryLabel}.`,
)
queryClient.invalidateQueries({
queryKey: ['itemSearch'],
......@@ -67,7 +80,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
}
},
onError() {
toast.error(`Failed to submit ${categoryLabel}.`)
toast.error(
`Failed to ${
isAllowedToPublish ? 'publish' : 'submit'
} ${categoryLabel}.`,
)
},
})
......@@ -146,7 +163,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
pristine || invalid || submitting || create.isLoading
}
>
Submit
{isAllowedToPublish ? 'Publish' : 'Submit'}
</Button>
</div>
</form>
......
import { useRouter } from 'next/router'
import { useQueryClient } from 'react-query'
import type { TrainingMaterialCore, TrainingMaterialDto } from '@/api/sshoc'
import { useUpdateTrainingMaterial } from '@/api/sshoc'
import {
TrainingMaterialCore,
TrainingMaterialDto,
useGetLoggedInUser,
useUpdateTrainingMaterial,
} from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ActorsFormSection } from '@/components/item/ActorsFormSection/ActorsFormSection'
import { MainFormSection } from '@/components/item/MainFormSection/MainFormSection'
......@@ -39,10 +43,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const toast = useToast()
const router = useRouter()
const auth = useAuth()
const user = useGetLoggedInUser()
const isAllowedToPublish =
user.data?.role !== undefined
? ['administrator', 'moderator'].includes(user.data.role)
: false
const queryClient = useQueryClient()
const create = useItemMutation({
onSuccess(data: TrainingMaterialDto) {
toast.success(`Successfully submitted ${categoryLabel}.`)
toast.success(
`Successfully ${
isAllowedToPublish ? 'published' : 'submitted'
} ${categoryLabel}.`,
)
queryClient.invalidateQueries({
queryKey: ['itemSearch'],
......@@ -69,7 +82,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
}
},
onError() {
toast.error(`Failed to submit ${categoryLabel}.`)
toast.error(
`Failed to ${
isAllowedToPublish ? 'publish' : 'submit'
} ${categoryLabel}.`,
)
},
})
......@@ -149,7 +166,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
pristine || invalid || submitting || create.isLoading
}
>
Submit
{isAllowedToPublish ? 'Publish' : 'Submit'}
</Button>
</div>
</form>
......
import { useRouter } from 'next/router'
import { useQueryClient } from 'react-query'
import type { WorkflowCore, WorkflowDto } from '@/api/sshoc'
import { useCreateWorkflow } from '@/api/sshoc'
import {
useCreateWorkflow,
useGetLoggedInUser,
WorkflowCore,
WorkflowDto,
} from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ActorsFormSection } from '@/components/item/ActorsFormSection/ActorsFormSection'
import { MainFormSection } from '@/components/item/MainFormSection/MainFormSection'
......@@ -37,10 +41,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const toast = useToast()
const router = useRouter()
const auth = useAuth()
const user = useGetLoggedInUser()
const isAllowedToPublish =
user.data?.role !== undefined
? ['administrator', 'moderator'].includes(user.data.role)
: false
const queryClient = useQueryClient()
const create = useItemMutation({
onSuccess(data: WorkflowDto) {
toast.success(`Successfully submitted ${categoryLabel}.`)
toast.success(
`Successfully ${
isAllowedToPublish ? 'published' : 'submitted'
} ${categoryLabel}.`,
)
queryClient.invalidateQueries({
queryKey: ['itemSearch'],
......@@ -67,7 +80,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
}
},
onError() {
toast.error(`Failed to submit ${categoryLabel}.`)
toast.error(
`Failed to ${
isAllowedToPublish ? 'publish' : 'submit'
} ${categoryLabel}.`,
)
},
})
......@@ -146,7 +163,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
pristine || invalid || submitting || create.isLoading
}
>
Submit
{isAllowedToPublish ? 'Publish' : 'Submit'}
</Button>
</div>
</form>
......
import { useRouter } from 'next/router'
import { useQueryClient } from 'react-query'
import type { WorkflowCore, WorkflowDto } from '@/api/sshoc'
import { useUpdateWorkflow } from '@/api/sshoc'
import {
useGetLoggedInUser,
useUpdateWorkflow,
WorkflowCore,
WorkflowDto,
} from '@/api/sshoc'
import type { ItemCategory, ItemSearchQuery } from '@/api/sshoc/types'
import { ActorsFormSection } from '@/components/item/ActorsFormSection/ActorsFormSection'
import { MainFormSection } from '@/components/item/MainFormSection/MainFormSection'
......@@ -39,10 +43,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const toast = useToast()
const router = useRouter()
const auth = useAuth()
const user = useGetLoggedInUser()
const isAllowedToPublish =
user.data?.role !== undefined
? ['administrator', 'moderator'].includes(user.data.role)
: false
const queryClient = useQueryClient()
const create = useItemMutation({
onSuccess(data: WorkflowDto) {
toast.success(`Successfully submitted ${categoryLabel}.`)
toast.success(
`Successfully ${
isAllowedToPublish ? 'published' : 'submitted'
} ${categoryLabel}.`,
)
queryClient.invalidateQueries({
queryKey: ['itemSearch'],
......@@ -69,7 +82,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
}
},
onError() {
toast.error(`Failed to submit ${categoryLabel}.`)
toast.error(
`Failed to ${
isAllowedToPublish ? 'publish' : 'submit'
} ${categoryLabel}.`,
)
},
})
......@@ -149,7 +166,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
pristine || invalid || submitting || create.isLoading
}
>
Submit
{isAllowedToPublish ? 'Publish' : 'Submit'}
</Button>
</div>
</form>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment