diff --git a/client/src/components/ArtistColorsWrapper.tsx b/client/src/components/ArtistColorsWrapper.tsx index 1c55e8804..498c23d4e 100644 --- a/client/src/components/ArtistColorsWrapper.tsx +++ b/client/src/components/ArtistColorsWrapper.tsx @@ -24,7 +24,6 @@ const colors = { }; const updateTheme = (artistColors?: any, theme?: "dark" | "light") => { - console.log("updatinmg theme", artistColors, theme); document.documentElement.setAttribute("data-mi-theme", theme ?? "light"); if (artistColors) { // document.documentElement.style.setProperty( @@ -83,8 +82,6 @@ const ArtistColorsWrapper: React.FC<{ children: React.ReactElement }> = ({ managedArtist?.properties?.colors ?? artist?.properties?.colors; React.useEffect(() => { - console.log("prefersDark", prefersDark.matches); - updateTheme(artistColors, prefersDark.matches ? "dark" : "light"); }, [artistColors]); diff --git a/client/src/components/ManageArtist/Posts/PostForm.tsx b/client/src/components/ManageArtist/Posts/PostForm.tsx index 51a262cb4..4ca0f79ae 100644 --- a/client/src/components/ManageArtist/Posts/PostForm.tsx +++ b/client/src/components/ManageArtist/Posts/PostForm.tsx @@ -22,7 +22,7 @@ import { ArtistButton } from "components/Artist/ArtistButtons"; import SavingInput from "../AlbumFormComponents/SavingInput"; import EditPostHeader from "./EditPostHeader"; -type FormData = { +export type PostFormData = { title: string; publishedAt: string; content: string; @@ -61,7 +61,7 @@ const PostForm: React.FC<{ multiple: true, }); - const methods = useForm({ + const methods = useForm({ defaultValues: post ? { ...post, @@ -97,7 +97,8 @@ const PostForm: React.FC<{ const publicationDate = watch("publishedAt"); const doSave = React.useCallback( - async (data: FormData) => { + async (data: PostFormData) => { + console.log("saving"); if (userId) { try { setIsSaving(true); diff --git a/client/src/components/ManageArtist/Posts/PublishPostButton.tsx b/client/src/components/ManageArtist/Posts/PublishPostButton.tsx index 51cb74670..8885aa9c5 100644 --- a/client/src/components/ManageArtist/Posts/PublishPostButton.tsx +++ b/client/src/components/ManageArtist/Posts/PublishPostButton.tsx @@ -1,4 +1,5 @@ import { ArtistButton } from "components/Artist/ArtistButtons"; +import { pick } from "lodash"; import React from "react"; import { useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; @@ -6,6 +7,7 @@ import api from "services/api"; import { useSnackbar } from "state/SnackbarContext"; import { useConfirm } from "utils/useConfirm"; import useGetUserObjectById from "utils/useGetUserObjectById"; +import { PostFormData } from "./PostForm"; const PublishPostButton: React.FC<{ post: Post; @@ -15,7 +17,7 @@ const PublishPostButton: React.FC<{ const snackbar = useSnackbar(); const [isPublishing, setIsPublishing] = React.useState(false); const { ask } = useConfirm(); - const { watch } = useFormContext(); + const { watch, handleSubmit } = useFormContext(); const { reload: reloadImages } = useGetUserObjectById( `manage/posts/${post?.id}/images`, @@ -29,33 +31,50 @@ const PublishPostButton: React.FC<{ const existingId = post.id; - const doPublish = React.useCallback(async () => { - try { - setIsPublishing(true); + const doPublish = React.useCallback( + async (data: PostFormData) => { + console.log("publishing"); + try { + setIsPublishing(true); - if (post.isDraft && (content === "" || content === "

")) { - const ok = await ask(t("contentIsEmpty")); - if (!ok) { - return; + if (post.isDraft && (content === "" || content === "

")) { + const ok = await ask(t("contentIsEmpty")); + if (!ok) { + return; + } } - } - if (post.isDraft && title === "") { - const ok = await ask(t("titleIsEmpty")); - if (!ok) { - return; + if (post.isDraft && title === "") { + const ok = await ask(t("titleIsEmpty")); + if (!ok) { + return; + } } + const picked = { + ...pick(data, ["title", "content", "isPublic", "shouldSendEmail"]), + publishedAt: new Date(data.publishedAt + ":00").toISOString(), + artistId: post.artistId, + minimumSubscriptionTierId: + isFinite(+data.minimumTier) && +data.minimumTier !== 0 + ? Number(data.minimumTier) + : undefined, + }; + await api.put, { result: { id: number } }>( + `manage/posts/${existingId}`, + picked + ); + await api.put(`manage/posts/${existingId}/publish`, {}); + reload(existingId); + reloadImages(); + snackbar(t("publishedPost"), { type: "success" }); + } catch (e) { + console.error(e); + } finally { + setIsPublishing(false); } - await api.put(`manage/posts/${existingId}/publish`, {}); - reload(existingId); - reloadImages(); - snackbar(t("publishedPost"), { type: "success" }); - } catch (e) { - console.error(e); - } finally { - setIsPublishing(false); - } - }, [existingId, title, content, isDraft]); + }, + [existingId, title, content, isDraft] + ); const minimumTier = watch("minimumTier"); const publicationDate = watch("publishedAt"); @@ -72,8 +91,8 @@ const PublishPostButton: React.FC<{ {publishText}