Skip to content

Commit

Permalink
fix: update typescript code
Browse files Browse the repository at this point in the history
  • Loading branch information
rpenido committed Jun 24, 2024
1 parent fabc561 commit ae93c8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
29 changes: 16 additions & 13 deletions src/library-authoring/create-library/CreateLibrary.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<string>();

const { noSpaceRule, specialCharsRule } = REGEX_RULES;
const validSlugIdRegex = /^[a-zA-Z\d]+(?:[\w -]*[a-zA-Z\d]+)*$/;
Expand All @@ -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,
Expand All @@ -63,6 +54,7 @@ const CreateLibrary = () => {
org: '',
slug: '',
}}

validationSchema={
Yup.object().shape({
title: Yup.string()
Expand All @@ -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) => (
<Form onSubmit={formikProps.handleSubmit}>
Expand Down
4 changes: 2 additions & 2 deletions src/library-authoring/create-library/data/api.ts
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down

0 comments on commit ae93c8e

Please sign in to comment.