-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle automatic publication after validation (#1265)
* feat: update frontend to handle automatic publication - warn the user that the item will set it to publish after the validation * chore(refactor): extract PublicationButton in individual components * feat: improve code from code review * feat: update query-client to 3.13.0
- Loading branch information
Showing
17 changed files
with
540 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/components/item/publish/publicationButtons/DescriptionElement.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
import { Typography } from '@mui/material'; | ||
|
||
type Props = { | ||
description: ReactNode; | ||
}; | ||
|
||
export const DescriptionElement = ({ description }: Props): ReactNode => { | ||
if (typeof description === 'string') { | ||
return <Typography>{description}</Typography>; | ||
} | ||
|
||
return description; | ||
}; | ||
|
||
export default DescriptionElement; |
73 changes: 73 additions & 0 deletions
73
src/components/item/publish/publicationButtons/InvalidButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { LoadingButton } from '@mui/lab'; | ||
|
||
import { PackedItem } from '@graasp/sdk'; | ||
|
||
import useModalStatus from '@/components/hooks/useModalStatus'; | ||
import { ADMIN_CONTACT } from '@/config/constants'; | ||
import { useBuilderTranslation } from '@/config/i18n'; | ||
import { mutations } from '@/config/queryClient'; | ||
import { buildItemPublicationButton } from '@/config/selectors'; | ||
import { BUILDER } from '@/langs/constants'; | ||
import { PublicationStatus } from '@/types/publication'; | ||
|
||
import PublicVisibilityModal from '../PublicVisibilityModal'; | ||
import PublicationButton from './PublicationButton'; | ||
|
||
type Props = { | ||
item: PackedItem; | ||
isLoading: boolean; | ||
}; | ||
|
||
const { usePostItemValidation } = mutations; | ||
|
||
export const InvalidButton = ({ item, isLoading }: Props): JSX.Element => { | ||
const { t } = useBuilderTranslation(); | ||
const { id: itemId, public: isPublic } = item; | ||
const { isOpen, openModal, closeModal } = useModalStatus(); | ||
|
||
const { mutate: validateItem, isLoading: isValidating } = | ||
usePostItemValidation(); | ||
|
||
const handleValidateItem = () => { | ||
if (isPublic) { | ||
validateItem({ itemId }); | ||
} else { | ||
openModal(); | ||
} | ||
}; | ||
|
||
const handleModalValidate = () => { | ||
validateItem({ itemId }); | ||
closeModal(); | ||
}; | ||
|
||
const description = t(BUILDER.LIBRARY_SETTINGS_VALIDATION_STATUS_FAILURE, { | ||
contact: ADMIN_CONTACT, | ||
}); | ||
|
||
return ( | ||
<> | ||
{!isPublic && ( | ||
<PublicVisibilityModal | ||
item={item} | ||
isOpen={isOpen} | ||
shouldUpdateVisibility={false} | ||
onClose={closeModal} | ||
onValidate={handleModalValidate} | ||
/> | ||
)} | ||
<PublicationButton isLoading={isLoading} description={description}> | ||
<LoadingButton | ||
variant="contained" | ||
onClick={handleValidateItem} | ||
loading={isValidating} | ||
data-cy={buildItemPublicationButton(PublicationStatus.Invalid)} | ||
> | ||
{t(BUILDER.LIBRARY_SETTINGS_RETRY_BUTTON)} | ||
</LoadingButton> | ||
</PublicationButton> | ||
</> | ||
); | ||
}; | ||
|
||
export default InvalidButton; |
Oops, something went wrong.