From ae93c8ea6457272267818e245eceed1dc2c86ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Mon, 24 Jun 2024 10:22:12 -0300 Subject: [PATCH] fix: update typescript code --- .../create-library/CreateLibrary.tsx | 29 ++++++++++--------- .../create-library/data/api.ts | 4 +-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/library-authoring/create-library/CreateLibrary.tsx b/src/library-authoring/create-library/CreateLibrary.tsx index 8cab743580..5c245d937f 100644 --- a/src/library-authoring/create-library/CreateLibrary.tsx +++ b/src/library-authoring/create-library/CreateLibrary.tsx @@ -1,5 +1,4 @@ // @ts-check -/* eslint-disable react/prop-types */ import React, { useState } from 'react'; import { StudioFooter } from '@edx/frontend-component-footer'; import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; @@ -22,11 +21,13 @@ import SubHeader from '../../generic/sub-header/SubHeader'; import { useCreateLibraryV2 } from './data/apiHooks'; import messages from './messages'; +import type { CreateContentLibraryDto } from './data/types'; + const CreateLibrary = () => { const intl = useIntl(); const navigate = useNavigate(); - const [apiError, setApiError] = useState(null); + const [apiError, setApiError] = useState(); const { noSpaceRule, specialCharsRule } = REGEX_RULES; const validSlugIdRegex = /^[a-zA-Z\d]+(?:[\w -]*[a-zA-Z\d]+)*$/; @@ -35,16 +36,6 @@ const CreateLibrary = () => { mutateAsync, } = useCreateLibraryV2(); - const onSubmit = async (values) => { - setApiError(null); - try { - const data = await mutateAsync(values); - navigate(`/library/${data.id}`); - } catch (/** @type {any} */ error) { - setApiError(error.message); - } - }; - const { data: organizationListData, isLoading: isOrganizationListLoading, @@ -63,6 +54,7 @@ const CreateLibrary = () => { org: '', slug: '', }} + validationSchema={ Yup.object().shape({ title: Yup.string() @@ -82,7 +74,18 @@ const CreateLibrary = () => { ), }) } - onSubmit={onSubmit} + + onSubmit={async (values: CreateContentLibraryDto) => { + setApiError(undefined); + try { + const data = await mutateAsync(values); + navigate(`/library/${data.id}`); + } catch (error) { + if (error instanceof Error) { + setApiError(error.message); + } + } + }} > {(formikProps) => (
diff --git a/src/library-authoring/create-library/data/api.ts b/src/library-authoring/create-library/data/api.ts index 6cd5b63b14..1587f47517 100644 --- a/src/library-authoring/create-library/data/api.ts +++ b/src/library-authoring/create-library/data/api.ts @@ -1,9 +1,9 @@ // @ts-check -import type { CreateContentLibraryDto } from './types'; - import { camelCaseObject, getConfig } from '@edx/frontend-platform'; import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; +import type { CreateContentLibraryDto } from './types'; + const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL; /**