Skip to content

Commit

Permalink
updating forms
Browse files Browse the repository at this point in the history
  • Loading branch information
iruzevic committed Jul 7, 2022
1 parent bd22429 commit bc9055c
Show file tree
Hide file tree
Showing 17 changed files with 1,232 additions and 1,206 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.

This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/).

## [1.2.5]
## [1.3.0]

### Fixed
- logic for scroll to top and scroll to first error.
Expand All @@ -16,6 +16,8 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a
### Added
- Method to remove all event listeners on demand.
- New event when all event listeners are removed.
- Filter for updating http_request_args.
- Better internal logging for integrations.

## [1.2.4]

Expand Down Expand Up @@ -66,7 +68,7 @@ This projects adheres to [Semantic Versioning](https://semver.org/) and [Keep a

- Initial production release.

[1.2.5]: https://github.com/infinum/eightshift-forms/compare/1.2.4...1.2.5
[1.3.0]: https://github.com/infinum/eightshift-forms/compare/1.2.4...1.3.0
[1.2.4]: https://github.com/infinum/eightshift-forms/compare/1.2.3...1.2.4
[1.2.3]: https://github.com/infinum/eightshift-forms/compare/1.2.2...1.2.3
[1.2.2]: https://github.com/infinum/eightshift-forms/compare/1.2.1...1.2.2
Expand Down
2 changes: 1 addition & 1 deletion eightshift-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Description: Eightshift form builder plugin.
* Author: Team Eightshift
* Author URI: https://eightshift.com/
* Version: 1.2.4
* Version: 1.3.0
* Text Domain: eightshift-forms
*
* @package EightshiftForms
Expand Down
2,261 changes: 1,067 additions & 1,194 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"webpack-cli": "^4.7.0"
},
"dependencies": {
"@eightshift/frontend-libs": "^6.0.5",
"@eightshift/frontend-libs": "^6.2.0",
"autosize": "^5.0.1",
"choices.js": "^10.1.0",
"dropzone": "^6.0.0-beta.1"
Expand Down
5 changes: 5 additions & 0 deletions src/Blocks/assets/styles/application-editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@

@import '@eightshift/frontend-libs/styles/es-utility-classes.scss';
@import '@eightshift/frontend-libs/styles/es-component-styles.scss';

// Hack for geo modal for select dropdown to work.
.es-geolocation-modal {
z-index: 1;
}
1 change: 1 addition & 0 deletions src/Blocks/custom/forms/components/forms-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const FormsOptions = ({ attributes, setAttributes, preview }) => {

{isModalOpen && (
<Modal
overlayClassName='es-geolocation-modal'
className='es-modal-max-width-l'
title={__('Geolocation rules', 'eightshift-form')}
shouldCloseOnClickOutside={false}
Expand Down
44 changes: 44 additions & 0 deletions src/General/General.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* File containing an class for general configuration.
*
* @package EightshiftForms\General
*/

declare(strict_types=1);

namespace EightshiftForms\General;

use EightshiftForms\Hooks\Filters;
use EightshiftFormsVendor\EightshiftLibs\Services\ServiceInterface;

/**
* Class General
*/
class General implements ServiceInterface
{
/**
* Register all hooks.
*
* @return void
*/
public function register(): void
{
\add_filter('http_request_args', [$this, 'getHttpRequestArgs']);
}

/**
* Return http request args.
*
* @param array<int, mixed> $args Arguments from core.
*
* @return array<int, mixed>
*/
public function getHttpRequestArgs(array $args): array
{
$args['timeout'] = 30;

return \apply_filters(Filters::getGeneralSettingsFilterName('httpRequestArgs'), $args); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase
}
}
6 changes: 4 additions & 2 deletions src/Helpers/UploadHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ protected function uploadFiles(array $files): array
$originalName = $fileValue['name'][$key];
$name = \md5((string) \time()) . '-' . \basename($originalName);
$tmpName = $fileValue['tmp_name'][$key];
$type = $fileValue['type'][$key];

// Create final folder location path.
$finalFilePath = $folderPath . \DIRECTORY_SEPARATOR . $name;
$finalFilePath = $folderPath . $name;

// Move the file to new location.
\move_uploaded_file($tmpName, $finalFilePath);
Expand All @@ -65,7 +66,8 @@ protected function uploadFiles(array $files): array
'index' => $key,
'fileName' => $originalName,
'name' => $name,
'path' => $finalFilePath
'path' => $finalFilePath,
'type' => $type,
];
}
}
Expand Down
26 changes: 25 additions & 1 deletion src/Hooks/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,10 @@ class Filters
],
'validation' => [
'failMimetypeValidationWhenFileNotOnFS' => 'force_mimetype_from_fs',
]
],
'general' => [
'httpRequestArgs' => 'http_request_args',
],
];

/**
Expand Down Expand Up @@ -362,4 +365,25 @@ public static function getValidationSettingsFilterName(string $name): string

return self::FILTER_PREFIX . "_validation_{$filter}";
}

/**
* Get General filter by name.
*
* @param string $name Filter name.
*
* @throws MissingFilterInfoException Throws error if filter name is missing or wrong.
*
* @return string
*
* @example filter_name es_forms_general_http_request_args
*/
public static function getGeneralSettingsFilterName(string $name): string
{
$filter = self::ALL_PUBLIC['general'][$name] ?? '';
if (!$filter) {
throw MissingFilterInfoException::viewException('general', '', $name);
}

return self::FILTER_PREFIX . "_general_{$filter}";
}
}
28 changes: 28 additions & 0 deletions src/Hooks/FiltersGeneral.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Filters General
This document will provide you with the code examples for forms filters used in general.

## Change http request arguments
This filter can be used to change CURL timeout for the file upload if you have to upload large files.

**Filter name:**
`es_forms_general_http_request_args`

**Filter example:**
```php
// Return http request args.
add_filter('es_forms_general_http_request_args', [$this, 'getHttpRequestArgs']);

/**
* Return http request args.
*
* @param array<int, mixed> $args Arguments from core.
*
* @return array<int, mixed>
*/
public function getHttpRequestArgs(array $args): array
{
$args['timeout'] = 50;

return $args;
}
```
6 changes: 3 additions & 3 deletions src/Hooks/FiltersValidation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ Using this filter, you can force Eightshift Forms to fail every file upload wher
**Filter example:**
```php
// Force mimetype validation from FS
add_filter('es_forms_validation_force_mimetype_from_fs', [$this, 'forceMimetypeFs'], 10, 2);
add_filter('es_forms_validation_force_mimetype_from_fs', [$this, 'forceMimetypeFs']);

/**
* Force mimetype validation from FS.
*
* @return bool
*/
public function forceMimetypeFs): bool
public function forceMimetypeFs(): bool
{
return true;
}
```
```
8 changes: 8 additions & 0 deletions src/Integrations/Clearbit/ClearbitClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ public function getApplication(string $emailKey, array $params, array $mapData):
);

if (\is_wp_error($response)) {
Helper::logger([
'integration' => 'clearbit',
'type' => 'wp',
'email' => $email,
'mapKeys' => $mapData,
'response' => $response,
]);
return [
'status' => 'error',
'code' => 400,
Expand All @@ -115,6 +122,7 @@ public function getApplication(string $emailKey, array $params, array $mapData):

return [
'status' => 'success',
'type' => 'service',
'code' => $code,
'message' => 'clearbitSuccess',
'email' => $email,
Expand Down
7 changes: 7 additions & 0 deletions src/Integrations/Goodbits/GoodbitsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public function postApplication(string $itemId, array $params, array $files, str
);

if (\is_wp_error($response)) {
Helper::logger([
'integration' => 'goodbits',
'type' => 'wp',
'body' => $body,
'response' => $response,
]);
return [
'status' => 'error',
'code' => 400,
Expand Down Expand Up @@ -141,6 +147,7 @@ public function postApplication(string $itemId, array $params, array $files, str

Helper::logger([
'integration' => 'goodbits',
'type' => 'service',
'body' => $body,
'response' => $response['response'],
'responseBody' => $responseBody,
Expand Down
14 changes: 12 additions & 2 deletions src/Integrations/Greenhouse/GreenhouseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ public function getItem(string $itemId): array
*/
public function postApplication(string $itemId, array $params, array $files, string $formId): array
{
$paramsPrepared = $this->prepareParams($params);

$body = \array_merge(
$this->prepareParams($params),
$paramsPrepared,
$this->prepareFiles($files)
);

Expand All @@ -142,6 +144,13 @@ public function postApplication(string $itemId, array $params, array $files, str
);

if (\is_wp_error($response)) {
Helper::logger([
'integration' => 'greenhouse',
'type' => 'wp',
'body' => $paramsPrepared,
'response' => $response,
]);

return [
'status' => 'error',
'code' => 400,
Expand Down Expand Up @@ -170,7 +179,8 @@ public function postApplication(string $itemId, array $params, array $files, str

Helper::logger([
'integration' => 'greenhouse',
'body' => $body,
'type' => 'service',
'body' => $paramsPrepared,
'response' => $response['response'],
'responseBody' => $responseBody,
'output' => $output,
Expand Down
7 changes: 7 additions & 0 deletions src/Integrations/Hubspot/HubspotClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ static function ($item) {
);

if (\is_wp_error($response)) {
Helper::logger([
'integration' => 'hubspot',
'type' => 'wp',
'body' => $body,
'response' => $response,
]);
return [
'status' => 'error',
'code' => 400,
Expand Down Expand Up @@ -271,6 +277,7 @@ static function ($item) {

Helper::logger([
'integration' => 'hubspot',
'type' => 'service',
'body' => $body,
'response' => $response['response'],
'responseBody' => $responseBody,
Expand Down
8 changes: 8 additions & 0 deletions src/Integrations/Mailchimp/MailchimpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ public function postApplication(string $itemId, array $params, array $files, str
);

if (\is_wp_error($response)) {
Helper::logger([
'integration' => 'mailchimp',
'type' => 'wp',
'body' => $body,
'response' => $response,
]);

return [
'status' => 'error',
'code' => 400,
Expand Down Expand Up @@ -205,6 +212,7 @@ public function postApplication(string $itemId, array $params, array $files, str

Helper::logger([
'integration' => 'mailchimp',
'type' => 'service',
'body' => $body,
'response' => $response['response'],
'responseBody' => $responseBody,
Expand Down
7 changes: 7 additions & 0 deletions src/Integrations/Mailerlite/MailerliteClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ public function postApplication(string $itemId, array $params, array $files, str
);

if (\is_wp_error($response)) {
Helper::logger([
'integration' => 'mailerlite',
'type' => 'wp',
'body' => $body,
'response' => $response,
]);
return [
'status' => 'error',
'code' => 400,
Expand Down Expand Up @@ -168,6 +174,7 @@ public function postApplication(string $itemId, array $params, array $files, str

Helper::logger([
'integration' => 'mailerlite',
'type' => 'service',
'body' => $body,
'response' => $response['response'],
'responseBody' => $responseBody,
Expand Down

0 comments on commit bc9055c

Please sign in to comment.