Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3096] Content-Create-Item: Added an identifier when user inputs meta… #3110

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/apps/content-editor/src/app/components/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default memo(function Editor({
modelZUID,
onUpdateFieldErrors,
fieldErrors,
metaData = undefined,
}) {
const dispatch = useDispatch();
const isNewItem = itemZUID.slice(0, 3) === "new";
Expand Down Expand Up @@ -290,12 +291,14 @@ export default memo(function Editor({
?.slice(0, 160) || ""
);

dispatch({
type: "SET_ITEM_WEB",
itemZUID,
key: "metaDescription",
value: cleanedValue,
});
if (!metaData?.metaDescription) {
dispatch({
type: "SET_ITEM_WEB",
itemZUID,
key: "metaDescription",
value: cleanedValue,
});
}

if ("og_description" in metaFields) {
dispatch({
Expand All @@ -317,7 +320,7 @@ export default memo(function Editor({
}
}
},
[fieldErrors, metaFields]
[fieldErrors, metaFields, metaData]
);

const applyDefaultValuesToItemData = useCallback(() => {
Expand Down
17 changes: 17 additions & 0 deletions src/apps/content-editor/src/app/views/ItemCreate/ItemCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ export const ItemCreate = () => {
const [SEOErrors, setSEOErrors] = useState<FieldErrors>({});
const metaRef = useRef(null);
const fieldErrorRef = useRef(null);
const [metaData, setMetaData] = useState({
metaDescription: item?.web?.metaDescription,
// metaTitle: item?.web?.metaTitle,
});

const [
createPublishing,
Expand Down Expand Up @@ -415,6 +419,12 @@ export const ItemCreate = () => {
isSaving={saving}
ref={metaRef}
errors={SEOErrors}
onChange={(value: string, name: string) =>
setMetaData((prev: any) => ({
...prev,
[name]: value,
}))
}
/>
)}
<Editor
Expand All @@ -436,6 +446,7 @@ export const ItemCreate = () => {
onUpdateFieldErrors={(errors: FieldErrors) => {
setFieldErrors(errors);
}}
metaData={metaData}
/>
{model.type !== "block" && (
<Meta
Expand All @@ -445,6 +456,12 @@ export const ItemCreate = () => {
isSaving={saving}
ref={metaRef}
errors={SEOErrors}
onChange={(value: string, name: string) =>
setMetaData((prev: any) => ({
...prev,
[name]: value,
}))
}
/>
)}
</AIGeneratorProvider>
Expand Down
14 changes: 12 additions & 2 deletions src/apps/content-editor/src/app/views/ItemEdit/Meta/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,19 @@ type MetaProps = {
onUpdateSEOErrors: (errors: Errors) => void;
errors: Errors;
errorComponent?: React.ReactNode;
onChange?: (value: string, name: string) => void;
};
export const Meta = forwardRef(
({ isSaving, onUpdateSEOErrors, errors, errorComponent }: MetaProps, ref) => {
(
{
isSaving,
onUpdateSEOErrors,
errors,
errorComponent,
onChange,
}: MetaProps,
ref
) => {
const dispatch = useDispatch();
const location = useLocation();
const isCreateItemPage = location?.pathname?.split("/")?.pop() === "new";
Expand Down Expand Up @@ -204,7 +214,7 @@ export const Meta = forwardRef(
}

onUpdateSEOErrors(currentErrors);

onChange && onChange(value, name);
dispatch({
// The og_image is stored as an ordinary field item and not a SEO field item
type: [...DYNAMIC_META_FIELD_NAMES, "og_image"].includes(name)
Expand Down
Loading