-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a table for code giveaways * WIP * Tests for batch insert * Fixes * Implement exporting * Rework manage page navigation, and add new page for code giveaways * Plural * Add some indexes * Add controllers * Add controller for csv export * Implement student endpoints * WIP * Enable CSV export * Fix conditional block * WIP add block to CMS * Block in CMS * WIP student interface * Refactor * WIP student frontend * System test fixes * System test fixes * Update snapshots * WIP test * WIP requirements * Sort translations * Update translations * Update * System test fixes
- Loading branch information
Showing
152 changed files
with
3,918 additions
and
964 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
97 changes: 97 additions & 0 deletions
97
services/cms/src/blocks/CodeGiveaway/CodeGiveawayBlockEditor.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,97 @@ | ||
import styled from "@emotion/styled" | ||
import { useQuery } from "@tanstack/react-query" | ||
import { InnerBlocks, InspectorControls } from "@wordpress/block-editor" | ||
import { BlockEditProps } from "@wordpress/blocks" | ||
import React, { useContext, useMemo } from "react" | ||
import { useTranslation } from "react-i18next" | ||
|
||
import PageContext from "../../contexts/PageContext" | ||
import { fetchCourseInstances } from "../../services/backend/course-instances" | ||
import { fetchCourseModulesByCourseId } from "../../services/backend/courses" | ||
import BlockPlaceholderWrapper from "../BlockPlaceholderWrapper" | ||
|
||
import { ConditionAttributes } from "." | ||
|
||
import InnerBlocksWrapper from "@/components/blocks/InnerBlocksWrapper" | ||
import CourseContext from "@/contexts/CourseContext" | ||
import { fetchCodeGiveawaysByCourseId } from "@/services/backend/code-giveaways" | ||
import DropdownMenu from "@/shared-module/common/components/DropdownMenu" | ||
import SelectField from "@/shared-module/common/components/InputFields/SelectField" | ||
import { assertNotNullOrUndefined } from "@/shared-module/common/utils/nullability" | ||
|
||
const ALLOWED_NESTED_BLOCKS = [ | ||
"core/heading", | ||
"core/buttons", | ||
"core/button", | ||
"core/paragraph", | ||
"core/image", | ||
"core/embed", | ||
] | ||
|
||
const Wrapper = styled.div` | ||
margin-left: 1rem; | ||
margin-right: 1rem; | ||
height: auto; | ||
` | ||
|
||
const CodeGiveawayBlockEditor: React.FC< | ||
React.PropsWithChildren<BlockEditProps<ConditionAttributes>> | ||
> = ({ attributes, clientId, setAttributes }) => { | ||
const { t } = useTranslation() | ||
const courseId = useContext(PageContext)?.page.course_id | ||
|
||
const codeGivawayQuery = useQuery({ | ||
queryKey: [`/code-giveaways/by-course/${courseId}`], | ||
queryFn: () => fetchCodeGiveawaysByCourseId(assertNotNullOrUndefined(courseId)), | ||
enabled: !!courseId, | ||
}) | ||
|
||
const title = useMemo(() => { | ||
let title = t("code-giveaway") | ||
if (codeGivawayQuery.data) { | ||
const selected = codeGivawayQuery.data.find((o) => o.id === attributes.code_giveaway_id) | ||
if (selected) { | ||
title += ` (${selected.name})` | ||
} | ||
} | ||
return title | ||
}, [attributes.code_giveaway_id, codeGivawayQuery.data, t]) | ||
|
||
const dropdownOptions = useMemo(() => { | ||
const res = [{ label: t("select-an-option"), value: "" }] | ||
if (!codeGivawayQuery.data) { | ||
return res | ||
} | ||
const additional = codeGivawayQuery.data.map((o) => ({ | ||
label: o.name, | ||
value: o.id, | ||
})) | ||
return res.concat(additional) | ||
}, [codeGivawayQuery.data, t]) | ||
|
||
return ( | ||
<BlockPlaceholderWrapper | ||
id={clientId} | ||
title={title} | ||
explanation={t("code-giveaway-explanation")} | ||
> | ||
<InspectorControls> | ||
{codeGivawayQuery.data && ( | ||
<Wrapper> | ||
<SelectField | ||
label={t("code-giveaway")} | ||
options={dropdownOptions} | ||
defaultValue={attributes.code_giveaway_id} | ||
onChangeByValue={(value) => setAttributes({ code_giveaway_id: value })} | ||
/> | ||
</Wrapper> | ||
)} | ||
</InspectorControls> | ||
<InnerBlocksWrapper title={t("instructions")}> | ||
<InnerBlocks allowedBlocks={ALLOWED_NESTED_BLOCKS} /> | ||
</InnerBlocksWrapper> | ||
</BlockPlaceholderWrapper> | ||
) | ||
} | ||
|
||
export default CodeGiveawayBlockEditor |
11 changes: 11 additions & 0 deletions
11
services/cms/src/blocks/CodeGiveaway/CodeGiveawayBlockSave.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,11 @@ | ||
import { InnerBlocks } from "@wordpress/block-editor" | ||
|
||
const CodeGiveawayBlockSave: React.FC = () => { | ||
return ( | ||
<div> | ||
<InnerBlocks.Content /> | ||
</div> | ||
) | ||
} | ||
|
||
export default CodeGiveawayBlockSave |
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,28 @@ | ||
/* eslint-disable i18next/no-literal-string */ | ||
import { BlockConfiguration } from "@wordpress/blocks" | ||
|
||
import { MOOCFI_CATEGORY_SLUG } from "../../utils/Gutenberg/modifyGutenbergCategories" | ||
|
||
import CodeGiveawayBlockEditor from "./CodeGiveawayBlockEditor" | ||
import CodeGiveawayBlockSave from "./CodeGiveawayBlockSave" | ||
|
||
export interface ConditionAttributes { | ||
code_giveaway_id: string | ||
} | ||
|
||
const ConditionalBlockConfiguration: BlockConfiguration<ConditionAttributes> = { | ||
title: "CodeGiveaway", | ||
description: | ||
"Used to place a code giveaway to a page. Make sure to have created a code giveaway in the manage page.", | ||
category: MOOCFI_CATEGORY_SLUG, | ||
attributes: { | ||
code_giveaway_id: { | ||
type: "string", | ||
default: "", | ||
}, | ||
}, | ||
edit: CodeGiveawayBlockEditor, | ||
save: CodeGiveawayBlockSave, | ||
} | ||
|
||
export default ConditionalBlockConfiguration |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { css } from "@emotion/css" | ||
|
||
const InnerBlocksWrapper: React.FC<React.PropsWithChildren<{ title: string }>> = ({ | ||
title, | ||
children, | ||
}) => { | ||
return ( | ||
<div | ||
className={css` | ||
width: 100%; | ||
border: 1px solid #e2e2e2; | ||
padding: 1rem; | ||
`} | ||
> | ||
<h4>{title}</h4> | ||
{children} | ||
</div> | ||
) | ||
} | ||
|
||
export default InnerBlocksWrapper |
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,8 @@ | ||
import { cmsClient } from "./cmsClient" | ||
|
||
import { validateResponse } from "@/shared-module/common/utils/fetching" | ||
|
||
export const fetchCodeGiveawaysByCourseId = async (courseId: string) => { | ||
const response = await cmsClient.get(`/code-giveaways/by-course/${courseId}`) | ||
return validateResponse(response, Array.isArray) | ||
} |
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
42 changes: 42 additions & 0 deletions
42
services/course-material/src/components/ContentRenderer/moocfi/CodeGiveAway/ClaimCode.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,42 @@ | ||
import { useTranslation } from "react-i18next" | ||
|
||
import { claimCodeFromCodeGiveaway } from "@/services/backend" | ||
import Button from "@/shared-module/common/components/Button" | ||
import ErrorBanner from "@/shared-module/common/components/ErrorBanner" | ||
import useToastMutation from "@/shared-module/common/hooks/useToastMutation" | ||
import { assertNotNullOrUndefined } from "@/shared-module/common/utils/nullability" | ||
|
||
interface ClaimCodeProps { | ||
codeGiveawayId: string | ||
onClaimed: () => void | ||
} | ||
|
||
const ClaimCode: React.FC<ClaimCodeProps> = ({ codeGiveawayId, onClaimed }) => { | ||
const { t } = useTranslation() | ||
|
||
const claimCodeMutation = useToastMutation( | ||
() => claimCodeFromCodeGiveaway(assertNotNullOrUndefined(codeGiveawayId)), | ||
{ notify: false }, | ||
) | ||
|
||
return ( | ||
<> | ||
{claimCodeMutation.isError && ( | ||
<ErrorBanner error={claimCodeMutation.error} variant="readOnly" /> | ||
)} | ||
<Button | ||
onClick={async () => { | ||
await claimCodeMutation.mutateAsync() | ||
onClaimed() | ||
}} | ||
variant="primary" | ||
size="medium" | ||
disabled={claimCodeMutation.isPending} | ||
> | ||
{t("claim-code")} | ||
</Button> | ||
</> | ||
) | ||
} | ||
|
||
export default ClaimCode |
Oops, something went wrong.