MCPcopy Create free account
hub / github.com/code100x/cms / handleContentSubmit

Function handleContentSubmit

src/components/admin/AddContent.tsx:73–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

71 };
72
73 const handleContentSubmit = async () => {
74 setLoading(true);
75 if (type === "appx") {
76 //@ts-ignore
77 metadata.appxVideoJSON = formatInputJSON(metadata.appxVideoJSON);
78 //@ts-ignore
79 if (!validateJSON(metadata.appxVideoJSON)) {
80 toast.error("Invalid JSON");
81 setLoading(false);
82 return;
83 }
84 }
85 const response = await fetch('/api/admin/content', {
86 body: JSON.stringify({
87 type,
88 thumbnail: imageUri,
89 title,
90 courseId,
91 parentContentId,
92 //* Metadata will be list of resolutions for normal videos and appxVideoId for appx videos
93 metadata,
94 adminPassword,
95 courseTitle,
96 rest,
97 discordChecked,
98 }),
99 method: 'POST',
100 headers: {
101 'Content-Type': 'application/json',
102 },
103 });
104 const responseData = await response.json();
105 setLoading(false);
106 if (response.status === 200) {
107 // handle success if needed
108 toast.success(responseData.message);
109 setTrigger((prev) => prev + 1); // why? trigger a re-render, this is a hack
110 setMetadata({});
111 } else {
112 // handle error if needed
113 toast.error(responseData.message || 'Something went wrong');
114 }
115 };
116
117 return (
118 <div className="grid grid-cols-1 gap-4 rounded-xl border-2 p-6 lg:grid-cols-7">

Callers

nothing calls this directly

Calls 2

formatInputJSONFunction · 0.85
validateJSONFunction · 0.85

Tested by

no test coverage detected