Skip to content

Commit

Permalink
[maykinmedia/open-producten#24] Bump formio-builder & add product pri…
Browse files Browse the repository at this point in the history
…ce component
  • Loading branch information
Floris272 committed Oct 16, 2024
1 parent bfc679d commit 122478b
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/openforms/formio/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
"map": "array",
"editgrid": "array",
"datetime": "datetime",
# TODO: product price?
}
1 change: 1 addition & 0 deletions src/openforms/forms/fd_translations_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def _move_translations(component: Component, locale: str, translations: dict[str
| "bsn"
| "addressNL"
| "npFamilyMembers"
| "productPrice"
| "cosign"
| "map"
| "postcode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {FormattedMessage} from 'react-intl';

import MessageList from 'components/admin/MessageList';

const CUSTOM_FIELD_TYPES = ['npFamilyMembers'];
const CUSTOM_FIELD_TYPES = ['npFamilyMembers']; // TODO: login required for Product Price?

const AuthenticationWarning = ({loginRequired, configuration}) => {
if (loginRequired) return null;
Expand Down
1 change: 1 addition & 0 deletions src/openforms/js/components/admin/form_design/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const OBJECTS_API_OBJECTTYPES_ENDPOINT = '/api/v2/objects-api/object-type
export const REGISTRATION_OBJECTS_TARGET_PATHS =
'/api/v2/registration/plugins/objects-api/target-paths';
export const AUTH_PLUGINS_ENDPOINT = '/api/v2/authentication/plugins';
export const PRODUCT_PRICES_ENDPOINT = '/api/v2/product_prices';
export const PREFILL_PLUGINS_ENDPOINT = '/api/v2/prefill/plugins';
export const DMN_PLUGINS_ENDPOINT = '/api/v2/dmn/plugins';
export const PAYMENT_PLUGINS_ENDPOINT = '/api/v2/payment/plugins';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const COMPONENT_DATATYPES = {
npFamilyMembers: 'object',
map: 'array',
editgrid: 'array',
// TODO: productPrices?
};

const DATATYPES_CHOICES = [
Expand Down
49 changes: 49 additions & 0 deletions src/openforms/js/components/form/productPrice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* A form widget to select product prices.
*/
import {Formio} from 'formiojs';

import {localiseSchema} from './i18n';
import {get} from '../../utils/fetch';
import {PRODUCT_PRICES_ENDPOINT} from '../admin/form_design/constants'; // TODO add new endpoint or add price options to existing one.

export const getProducts = async () => {
const response = await get(PRODUCT_PRICES_ENDPOINT);
return response.data.map(item => ({
label: item.name,
value: item.uuid,
}));
};

const Select = Formio.Components.components.select;

class ProductPrice extends Select {
static schema(...extend) {
const schema = Select.schema(
{
label: 'Select a product',
key: 'productPrice',
type: 'productPrice',
product: ''
},
...extend
);
return localiseSchema(schema);
}

static get builderInfo() {
return {
title: 'Product Price',
icon: 'file',
group: 'basic',
weight: 10,
schema: ProductPrice.schema(),
};
}

get defaultSchema() {
return ProductPrice.schema();
}
}

export default ProductPrice;
2 changes: 2 additions & 0 deletions src/openforms/js/components/formio_builder/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {IntlProvider} from 'react-intl';
import {getIntlProviderProps} from 'components/admin/i18n';
import {getAvailableAuthPlugins} from 'components/form/cosign';
import {getAvailableDocumentTypes} from 'components/form/file';
import {getProducts} from '../form/productPrice';
import {getComponentEmptyValue} from 'components/utils';
import jsonScriptToVar from 'utils/json-script';
import {currentTheme} from 'utils/theme';
Expand Down Expand Up @@ -172,6 +173,7 @@ class WebformBuilder extends WebformBuilderFormio {
getDocumentTypes={async () => await getAvailableDocumentTypes(this)}
getConfidentialityLevels={async () => CONFIDENTIALITY_LEVELS}
getAuthPlugins={getAvailableAuthPlugins}
getProducts={getProducts}
// Component/builder state
isNew={isNew}
component={builderData}
Expand Down
1 change: 1 addition & 0 deletions src/openforms/js/components/formio_builder/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const getBuilderOptions = () => {
licenseplate: true,
bsn: true,
npFamilyMembers: true,
productPrice: true,
signature: true,
cosign: true,
map: true,
Expand Down
2 changes: 2 additions & 0 deletions src/openforms/js/formio_module.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import IbanField from './components/form/iban';
import LicensePlate from './components/form/licenseplate';
import Map from './components/form/map';
import NpFamilyMembers from './components/form/np-family-members';
import ProductPrice from './components/form/productPrice';
import NumberField from './components/form/number';
import PasswordField from './components/form/password';
import PhoneNumberField from './components/form/phoneNumber';
Expand Down Expand Up @@ -58,6 +59,7 @@ const FormIOModule = {
coSign: CoSignFieldOld,
cosign: CoSignField,
npFamilyMembers: NpFamilyMembers,
productPrice: ProductPrice,
columns: ColumnField,
content: ContentField,
currency: CurrencyField,
Expand Down

0 comments on commit 122478b

Please sign in to comment.