Skip to content

Commit

Permalink
Merge pull request #1116 from EscolaLMS/feature/WELLMS-517
Browse files Browse the repository at this point in the history
Feature/wellms 517
  • Loading branch information
victazzz authored Jan 23, 2025
2 parents 5659423 + ccd0515 commit b9b3473
Show file tree
Hide file tree
Showing 17 changed files with 287 additions and 56 deletions.
8 changes: 6 additions & 2 deletions src/hooks/useMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ export const useShowNotification = () => {
id: translationKey,
},
{
model: model ? intl.formatMessage({ id: model }) : undefined,
id: model ? intl.formatMessage({ id: model.toLocaleLowerCase() }) : undefined,
},
),
);
} else {
message[isSuccess ? 'success' : 'error'](
isSuccess
? (response.message as string)
? response.message
? (response.message as string)
: intl.formatMessage({
id: 'updated_at',
})
: intl.formatMessage({
id: 'notifications.unexpectedError',
}),
Expand Down
2 changes: 2 additions & 0 deletions src/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export default {
draft: 'Draft',
published: 'Published',
archived: 'Archived',
assigne: 'Assignee',
slug: 'Slug',
name: 'Name',
ID: 'ID',
Expand Down Expand Up @@ -622,6 +623,7 @@ export default {
users_attached: 'Users Attached',
generate_token: 'Generate youtube token',
browse: 'Browse files',
dictionary: 'Dictionary',
related_products: 'Related Products',
selected_products: 'Selected objects',
quantity: 'Quantity',
Expand Down
2 changes: 2 additions & 0 deletions src/locales/pl-PL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export default {
answers: 'Odpowiedzi',
Inactive: 'Nieaktywny',
inactive: 'Nieaktywny',
assignee: 'Przypisz',
address: 'Adres',
draft: 'Roboczy',
published: 'Opublikowany',
Expand Down Expand Up @@ -865,6 +866,7 @@ export default {
Unknown: 'Nieznany',
edit_score: 'Edytuj wynik',
see_file_example_image: 'Zobacz zdjęcie przykładowego pliku',
dictionary: 'Słownik',
edit_dictionary: 'Edytuj słownik',
new_dictionary: 'Dodaj słownik',
free_views_count: 'Liczba bezpłatnych wyświetleń',
Expand Down
12 changes: 12 additions & 0 deletions src/pages/Categories/components/ModalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ export const CategoryModalForm: React.FC<{
rules={[
{
required: true,
validator: async (_, value) => {
if (!value) {
return Promise.reject(
new Error(
intl.formatMessage({
id: 'field_required',
}),
),
);
}
return Promise.resolve();
},
},
]}
name="name"
Expand Down
28 changes: 24 additions & 4 deletions src/pages/Consultations/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import ProFormImageUpload from '@/components/ProFormImageUpload';
import ProductWidget from '@/components/ProductWidget';
import UserSelect from '@/components/UserSelect';
import UserSubmissions from '@/components/UsersSubmissions';
import { ModelStatus } from '@/consts/status';
import { useShowNotification } from '@/hooks/useMessage';
import useModelFields from '@/hooks/useModelFields';
import useValidateFormEdit from '@/hooks/useValidateFormEdit';
Expand All @@ -32,6 +31,7 @@ import {
} from '@/services/escola-lms/consultations';
import { settings } from '@/services/escola-lms/settings';
import { categoriesArrToIds, splitImagePath } from '@/utils/utils';
import { createRequiredFieldValidator } from '@/utils/validate';
import { useCallback } from 'react';
import { FormattedMessage, history, useIntl, useParams } from 'umi';
import ConsultationCalendar from './components/Calendar';
Expand All @@ -57,7 +57,7 @@ const ConsultationForm = () => {
const { manageCourseEdit, setManageCourseEdit, validateCourseEdit } = useValidateFormEdit();
const [form] = ProForm.useForm();
const additionalFields = useModelFields('EscolaLms\\Consultations\\Models\\Consultation');

const requiredValidator = createRequiredFieldValidator(intl);
const [showScreenSaves, setShowScreenSaves] = useState<boolean>(false);
const { showNotification } = useShowNotification();
const fetchData = useCallback(async () => {
Expand Down Expand Up @@ -245,6 +245,11 @@ const ConsultationForm = () => {
})}
required
disabled={manageCourseEdit.disableEdit}
rules={[
{
validator: requiredValidator,
},
]}
/>

<ProFormText
Expand Down Expand Up @@ -277,11 +282,21 @@ const ConsultationForm = () => {
defaultMessage: 'archived',
}),
}}
initialValue={ModelStatus.draft}
placeholder={intl.formatMessage({
id: 'status',
})}
rules={[{ required: true, message: <FormattedMessage id="select" /> }]}
rules={[
{
required: true,
message: <FormattedMessage id="select" />,
validator: (_, value) => {
if (!value) {
return Promise.reject(new Error(intl.formatMessage({ id: 'select' })));
}
return Promise.resolve();
},
},
]}
disabled={manageCourseEdit.disableEdit}
/>
</ProForm.Group>
Expand Down Expand Up @@ -352,6 +367,11 @@ const ConsultationForm = () => {
width: 440,
}}
required
rules={[
{
validator: requiredValidator,
},
]}
>
<WysiwygMarkdown directory={`consultation/${consultation}/wysiwyg`} />
</ProForm.Item>
Expand Down
21 changes: 14 additions & 7 deletions src/pages/Courses/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export default () => {
...manageCourseEdit,
valuesChanged: true,
});

if (values.active_from) {
setFromDateValidation(values.active_from);
}
Expand Down Expand Up @@ -191,6 +192,7 @@ export default () => {
});
},
initialValues: data,
validate: true,
form,
}),
[course, data, manageCourseEdit, form],
Expand Down Expand Up @@ -484,17 +486,22 @@ export default () => {
defaultMessage: 'published_unactivated',
}),
}}
initialValue={{
draft: intl.formatMessage({
id: 'draft',
defaultMessage: 'draft',
}),
}}
placeholder={intl.formatMessage({
id: 'status',
})}
disabled={manageCourseEdit.disableEdit}
rules={[{ required: true, message: <FormattedMessage id="select" /> }]}
rules={[
{
required: true,
message: <FormattedMessage id="select" />,
validator: (_, value) => {
if (!value) {
return Promise.reject(new Error(intl.formatMessage({ id: 'select' })));
}
return Promise.resolve();
},
},
]}
/>
<ProFormText
width="sm"
Expand Down
24 changes: 21 additions & 3 deletions src/pages/Dictionary/form.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useShowNotification } from '@/hooks/useMessage';
import DictionaryWordsTableList from '@/pages/Dictionary/components/DictionaryWords';
import {
createDictionary,
Expand All @@ -7,7 +8,7 @@ import {
import ProCard from '@ant-design/pro-card';
import ProForm, { ProFormDigit, ProFormText } from '@ant-design/pro-form';
import { PageContainer } from '@ant-design/pro-layout';
import { Col, Row, Spin, message } from 'antd';
import { Col, Row, Spin } from 'antd';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { FormattedMessage, history, useIntl, useParams } from 'umi';

Expand All @@ -26,7 +27,7 @@ export default () => {
const params = useParams<{ dictionaryId?: string; tab?: string }>();
const { dictionaryId, tab } = params;
const isNew = dictionaryId === 'new';

const { showNotification } = useShowNotification();
const [data, setData] = useState<Partial<API.Dictionaries>>();
const [loading, setLoading] = useState(false);
const [form] = ProForm.useForm();
Expand Down Expand Up @@ -63,7 +64,7 @@ export default () => {
response = await updateDictionary(Number(dictionaryId), values);
}

message.success(response.message);
showNotification(response);
},
initialValues: data,
}),
Expand Down Expand Up @@ -101,6 +102,23 @@ export default () => {
id: 'Name',
})}
required
rules={[
{
validator: async (_, value) => {
if (!value) {
return Promise.reject(
new Error(
intl.formatMessage({
id: 'field_required',
defaultMessage: 'field_required',
}),
),
);
}
return Promise.resolve();
},
},
]}
/>
</Col>
{!isNew && (
Expand Down
17 changes: 17 additions & 0 deletions src/pages/Pages/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import WysiwygMarkdown from '@/components/WysiwygMarkdown';
import { PageContainer } from '@ant-design/pro-layout';

import { slugify } from '@/services/escola-lms/slug';
import { createRequiredFieldValidator } from '@/utils/validate';
import { useCallback } from 'react';
import { FormattedMessage, history, useIntl, useParams } from 'umi';

Expand All @@ -16,6 +17,7 @@ export default () => {
const params = useParams<{ page?: string }>();
const { page } = params;
const isNew = page === 'new';
const requiredValidator = createRequiredFieldValidator(intl);

const [data, setData] = useState<Partial<API.Page>>();
const [form] = ProForm.useForm();
Expand Down Expand Up @@ -95,6 +97,11 @@ export default () => {
id: 'title',
})}
required
rules={[
{
validator: requiredValidator,
},
]}
/>
<ProFormText
width="md"
Expand All @@ -106,6 +113,11 @@ export default () => {
})}
disabled
required
rules={[
{
validator: requiredValidator,
},
]}
/>
<ProFormSwitch name="active" label={<FormattedMessage id="is_active" />} />
</ProForm.Group>
Expand All @@ -116,6 +128,11 @@ export default () => {
tooltip={<FormattedMessage id="content_tooltip" />}
valuePropName="value"
required
rules={[
{
validator: requiredValidator,
},
]}
>
<WysiwygMarkdown directory={`pages/${page}/wysiwyg`} />
</ProForm.Item>
Expand Down
26 changes: 13 additions & 13 deletions src/pages/Products/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import PACKAGES from '@/consts/packages';
import { useShowNotification } from '@/hooks/useMessage';
import { createHavePackageInstalled } from '@/utils/access';
import { categoriesArrToIds, tagsArrToIds } from '@/utils/utils';
import { createRequiredFieldValidator } from '@/utils/validate';
import { ProFormSelect } from '@ant-design/pro-components';
import ProTable from '@ant-design/pro-table';
import UserAccess from './UserAccess';
Expand Down Expand Up @@ -102,7 +103,7 @@ const ProductsForm: React.FC<{
onProductSaved?: (model: EscolaLms.Cart.Models.Product) => void;
}> = ({ tab = 'attributes', onTabChange, id, productable, onProductSaved, type = 'card' }) => {
const intl = useIntl();

const requiredValidator = createRequiredFieldValidator(intl);
const [productId, setProductId] = useState<string | number | undefined>(id);
const [currProductables, setCurrProductables] = useState<MinimumProductProductable[]>([]);
const isNew = useMemo(() => productId === 'new', [productId]);
Expand Down Expand Up @@ -235,17 +236,11 @@ const ProductsForm: React.FC<{

const postData = {
...values,
productables: [
{
id: 134,
morph_class: 'App\\Models\\awdawd',
productable_id: 134,
productable_type: 'App\\Models\\awdwa',
quantity: 1,
name: 'new21412421',
description: 'adawd',
},
],
productables: currProductables
? getProductables(
currProductables as string[] | string | API.ProductableResourceListItem[],
)
: undefined,
...(values.related_products ? { related_products } : {}),
fields: {
in_app_purchase_ids: {
Expand Down Expand Up @@ -336,6 +331,11 @@ const ProductsForm: React.FC<{
defaultMessage: 'name',
})}
required
rules={[
{
validator: requiredValidator,
},
]}
/>
<ProForm.Item
shouldUpdate
Expand Down Expand Up @@ -426,7 +426,7 @@ const ProductsForm: React.FC<{
<ProFormDigit
rules={[
{
required: true,
validator: requiredValidator,
},
]}
width="xs"
Expand Down
14 changes: 13 additions & 1 deletion src/pages/Roles/components/ModalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ export const RolesModalForm: React.FC<{
label={<FormattedMessage id="name" defaultMessage="name" />}
rules={[
{
required: true,
validator: async (_, value) => {
if (!value) {
return Promise.reject(
new Error(
intl.formatMessage({
id: 'field_required',
defaultMessage: 'field_required',
}),
),
);
}
return Promise.resolve();
},
},
]}
width="md"
Expand Down
Loading

0 comments on commit b9b3473

Please sign in to comment.