-
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.
Merge remote-tracking branch 'origin/master' into flip-card-block
- Loading branch information
Showing
258 changed files
with
8,658 additions
and
2,147 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[toolchain] | ||
channel = "1.76" | ||
channel = "1.80" | ||
profile = "default" |
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
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
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
Oops, something went wrong.