Skip to content

Commit

Permalink
Merge pull request #40 from thrivedesk/fixes/portal_issue
Browse files Browse the repository at this point in the history
feat(portal): cache Implemented and style fixed
  • Loading branch information
Rijoanul-Shanto authored Apr 5, 2023
2 parents bcab55c + f0ff736 commit b556abc
Show file tree
Hide file tree
Showing 19 changed files with 397 additions and 186 deletions.
2 changes: 1 addition & 1 deletion assets/css/admin.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/css/thrivedesk.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/conversation.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions assets/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"/js/admin.js": "/js/admin.js?id=18b67b93110a65207fc236b13f1d942f",
"/js/conversation.js": "/js/conversation.js?id=86c19b8417f013676b42350cd0aeb416",
"/css/thrivedesk.css": "/css/thrivedesk.css?id=262e46f459b3501e944e9e8ea3253933",
"/css/admin.css": "/css/admin.css?id=64c236cd5ab367476f1f642a853ff94a"
"/js/admin.js": "/js/admin.js?id=3dfc0893dc6b892861faaabab15795eb",
"/js/conversation.js": "/js/conversation.js?id=f350f8190000681d788eddae98eda48c",
"/css/thrivedesk.css": "/css/thrivedesk.css?id=eccc932772423da101d45962ee87d101",
"/css/admin.css": "/css/admin.css?id=45030a5be426549e45aa300b5a9d9f30"
}
32 changes: 32 additions & 0 deletions includes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,35 @@ function get_td_helpdesk_options() {
return get_option('td_helpdesk_settings', []);
}
}

if (!function_exists('remove_thrivedesk_cache_by_key')) {
function remove_thrivedesk_cache_by_key(string $key) {
delete_transient($key);
}
}

if (!function_exists('remove_thrivedesk_all_cache')) {
function remove_thrivedesk_all_cache() {
global $wpdb;
$wpdb->query(
"DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_thrivedesk_%'
OR option_name LIKE '_transient_timeout_thrivedesk_%'");
}
}

if (!function_exists('remove_thrivedesk_conversation_cache')) {
function remove_thrivedesk_conversation_cache() {
global $wpdb;
$wpdb->query(
"DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_thrivedesk_conversation%' ");
}
}

/*
* Clear cache from ajax call
*/
add_action('wp_ajax_thrivedesk_clear_cache', function () {
remove_thrivedesk_all_cache();
remove_thrivedesk_conversation_cache();
wp_send_json_success();
});
111 changes: 55 additions & 56 deletions includes/views/pages/settings.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
$td_helpdesk_selected_option = get_td_helpdesk_options();
$td_selected_post_types = $td_helpdesk_selected_option['td_helpdesk_post_types'] ?? [];
$td_organizations = \ThriveDesk\Assistants\Assistant::organizations() ?? [];
$td_assistants = \ThriveDesk\Assistants\Assistant::get_assistants() ?? [];
$td_api_key = $td_helpdesk_selected_option['td_helpdesk_api_key'] ?? '';
$is_portal_allowed = (new \ThriveDesk\Services\PortalService())->is_allowed_portal_feature();
use ThriveDesk\Assistants\Assistant;
use ThriveDesk\Services\PortalService;

$td_helpdesk_selected_option = get_td_helpdesk_options();
$td_selected_post_types = $td_helpdesk_selected_option['td_helpdesk_post_types'] ?? [];
$td_assistants = Assistant::assistants();
$td_api_key = $td_helpdesk_selected_option['td_helpdesk_api_key'] ?? '';
$has_portal_access = ( new PortalService() )->has_portal_access();
?>

<div class="hidden tab-settings">
Expand Down Expand Up @@ -55,64 +57,61 @@
<p><?php _e( 'Help center inside your website. Customer can create and reply tickets, access Knowledge base.',
'thrivedesk' ); ?></p>
<div class="td-card">

<?php if (empty(get_td_helpdesk_options()['td_helpdesk_api_key'])): ?>
<div class="alert alert-info" id="no_api_key_alert">
<?php _e('You need to add the API key above ☝️ to use the Portal feature inside your site.', 'thrivedesk');?>
</div>
<?php endif; ?>

<?php elseif (!$is_portal_allowed): ?>
<?php // check the plan, if not PRO or above then, show the below warning ?>
<div class="alert alert-danger">
<?php _e('Portal feature is available from the PRO plan and above. Please upgrade your subscription', 'thrivedesk');?>
<a class="text-blue-500" href="https://app.thrivedesk.com/billing/plans" target="_blank"><?php _e( 'here', 'thrivedesk' ); ?></a>.
</div>
<?php else: ?>
<div class="flex space-x-4 <?php echo empty($td_api_key) ? 'hidden' : ''; ?>" id="td_post_content">
<div class="space-y-4 flex-1">
<div class="space-y-2">
<label for="td_helpdesk_page_id" class="font-medium text-black text-sm"><?php _e( 'New Ticket Page', 'thrivedesk' ); ?></label>
<select id="td_helpdesk_page_id" class="mt-1 bg-gray-50 border border-gray-300 rounded px-2 py-1 w-full max-w-full">
<option value=""> <?php _e( 'Select a page', 'thrivedesk' ); ?> </option>
<?php foreach ( get_pages() as $key => $page ) : ?>
<option value="<?php echo $page->ID; ?>" <?php echo array_key_exists( 'td_helpdesk_page_id',
$td_helpdesk_selected_option ) && $td_helpdesk_selected_option['td_helpdesk_page_id'] == $page->ID ? 'selected' : '' ?> >
<?php echo $page->post_title; ?>
</option>
<?php endforeach; ?>
</select>
<div><?php _e( 'Use any form plugin to create new ticket page or use existing one. Learn more ','thrivedesk' ); ?><a class="text-blue-500" href="#">here</a>.</div>
</div>
<div class="space-y-2">
<label for="td_helpdesk_post_types" class="font-medium text-black text-sm"><?php _e( 'Search Provider', 'thrivedesk' ); ?></label>
<?php
$wp_post_types = array_filter( get_post_types( array(
'public' => true,
'show_in_rest' => true
) ), function ( $type ) {
return $type !== 'attachment';
} ); ?>
<div class="flex items-center space-x-2">
<?php foreach ( $wp_post_types as $post_type ) : ?>
<div>
<input class="td_helpdesk_post_types" type="checkbox"
name="td_helpdesk_post_types[]"
value="<?php echo esc_attr( $post_type ); ?>" <?php echo in_array( $post_type,
$td_selected_post_types ) ? 'checked' : ''; ?>>
<label for="<?php echo esc_attr( $post_type ); ?>"> <?php echo esc_html( ucfirst( $post_type ) ); ?> </label>
</div>
<?php endforeach; ?>
</div>
<div><?php _e( 'Select a post type where user can search before raise a support ticket', 'thrivedesk' ); ?>.</div>
</div>
<div class="alert alert-danger hidden" id="portal_feature">
<?php _e('Portal feature is available from the PRO plan and above. Please upgrade your subscription', 'thrivedesk');?>
<a class="text-blue-500" href="https://app.thrivedesk.com/billing/plans" target="_blank"><?php _e( 'here', 'thrivedesk' ); ?></a>.
</div>

<div class="flex space-x-4 <?php echo ($has_portal_access && !empty($td_api_key)) ? '' : 'hidden' ?>" id="td_post_content">
<div class="space-y-4 flex-1">
<div class="space-y-2">
<label for="td_helpdesk_page_id" class="font-medium text-black text-sm"><?php _e( 'New Ticket Page', 'thrivedesk' ); ?></label>
<select id="td_helpdesk_page_id" class="mt-1 bg-gray-50 border border-gray-300 rounded px-2 py-1 w-full max-w-full">
<option value=""> <?php _e( 'Select a page', 'thrivedesk' ); ?> </option>
<?php foreach ( get_pages() as $key => $page ) : ?>
<option value="<?php echo $page->ID; ?>" <?php echo array_key_exists( 'td_helpdesk_page_id',
$td_helpdesk_selected_option ) && $td_helpdesk_selected_option['td_helpdesk_page_id'] == $page->ID ? 'selected' : '' ?> >
<?php echo $page->post_title; ?>
</option>
<?php endforeach; ?>
</select>
<div><?php _e( 'Use any form plugin to create new ticket page or use existing one. Learn more ','thrivedesk' ); ?><a class="text-blue-500" href="#">here</a>.</div>
</div>
<div class="p-4 bg-stone-100 border rounded w-64">
<div class="text-base font-semibold"><?php _e( 'Shortcode', 'thrivedesk' ); ?></div>
<code class="my-2 inline-block">[thrivedesk_portal]</code>
<p><?php _e( 'Portal can only be accessible by logged in users', 'thrivedesk' ); ?>.</p>
<div class="space-y-2">
<label for="td_helpdesk_post_types" class="font-medium text-black text-sm"><?php _e( 'Search Provider', 'thrivedesk' ); ?></label>
<?php
$wp_post_types = array_filter( get_post_types( array(
'public' => true,
'show_in_rest' => true
) ), function ( $type ) {
return $type !== 'attachment';
} ); ?>
<div class="flex items-center space-x-2">
<?php foreach ( $wp_post_types as $post_type ) : ?>
<div>
<input class="td_helpdesk_post_types" type="checkbox"
name="td_helpdesk_post_types[]"
value="<?php echo esc_attr( $post_type ); ?>" <?php echo in_array( $post_type,
$td_selected_post_types ) ? 'checked' : ''; ?>>
<label for="<?php echo esc_attr( $post_type ); ?>"> <?php echo esc_html( ucfirst( $post_type ) ); ?> </label>
</div>
<?php endforeach; ?>
</div>
<div><?php _e( 'Select a post type where user can search before raise a support ticket', 'thrivedesk' ); ?>.</div>
</div>
</div>
<?php endif; ?>
<div class="p-4 bg-stone-100 border rounded w-64">
<div class="text-base font-semibold"><?php _e( 'Shortcode', 'thrivedesk' ); ?></div>
<code class="my-2 inline-block">[thrivedesk_portal]</code>
<p><?php _e( 'Portal can only be accessible by logged in users', 'thrivedesk' ); ?>.</p>
</div>
</div>
</div>
</div>
<button type="submit" id="td_setting_btn_submit" class="btn-primary">
Expand Down
8 changes: 6 additions & 2 deletions includes/views/setting.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php

use ThriveDesk\Assistants\Assistant;

$edd = ThriveDesk\Plugins\EDD::instance();
$woocommerce = ThriveDesk\Plugins\WooCommerce::instance();
$fluentcrm = ThriveDesk\Plugins\FluentCRM::instance();
$wppostsync = ThriveDesk\Plugins\WPPostSync::instance();
$autonami = ThriveDesk\Plugins\Autonami::instance();
// $smartpay = ThriveDesk\Plugins\SmartPay::instance();

$assistants = \ThriveDesk\Assistants\Assistant::get_assistants()['assistants'] ?? [];
$assistant_settings = \ThriveDesk\Assistants\Assistant::get_assistant_settings();
$assistant_settings = Assistant::get_assistant_settings();
$plugins = [
[
'namespace' => 'woocommerce',
Expand Down Expand Up @@ -87,6 +88,9 @@
<a href="https://help.thrivedesk.com/en" target="_blank">
<?php _e( 'Help Center', 'thrivedesk' ) ?>
</a>
<button id="thrivedesk_clear_cache_btn" class="hover:text-blue-600">
<?php _e( 'Clear Cache', 'thrivedesk' ) ?>
</button>
<a href="https://status.thrivedesk.com/" target="_blank">
<?php _e( 'System Status', 'thrivedesk' ) ?>
</a>
Expand Down
10 changes: 7 additions & 3 deletions includes/views/shortcode/conversation-details.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php

use ThriveDesk\Conversations\Conversation;
use ThriveDesk\Services\PortalService;

$td_reply_nonce = wp_create_nonce('td-reply-conversation-action');
const ACTOR_TYPE = 'ThriveDesk\\Models\\User';

if (isset($_GET['td_conversation_id'])) {
$conversation = \ThriveDesk\Conversations\Conversation::get_conversation($_GET['td_conversation_id']);
$is_portal_available = (new ThriveDesk\Services\PortalService())->is_allowed_portal_feature();
$conversation = Conversation::get_conversation($_GET['td_conversation_id']);
$is_portal_available = (new PortalService())->has_portal_access();
}
?>
<?php if ($is_portal_available && $conversation): ?>
Expand Down Expand Up @@ -46,7 +50,7 @@
</div>
<div class="td-conversation-body">
<?php if ($event['event']['html_body']): ?>
<?php echo \ThriveDesk\Conversations\Conversation::validate_conversation_body($event['event']['html_body']); ?>
<?php echo Conversation::validate_conversation_body($event['event']['html_body']); ?>
<?php elseif($event['event']['text_body']): ?>
<?php echo $event['event']['text_body']; ?>
<?php endif; ?>
Expand Down
3 changes: 2 additions & 1 deletion includes/views/shortcode/conversations.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
use ThriveDesk\Conversations\Conversation;
use ThriveDesk\Services\PortalService;

$conversations = Conversation::get_conversations();
$conversation_data = isset($conversations['data']) ? Conversation::td_conversation_sort_by_status($conversations['data']) : [];
$links = $conversations['meta']['links'] ?? [];
$is_portal_available = (new ThriveDesk\Services\PortalService())->is_allowed_portal_feature();
$is_portal_available = (new PortalService())->has_portal_access();

?>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thrivedesk",
"version": "1.0.3",
"version": "1.0.4",
"description": "ThriveDesk - Customer Support & Helpdesk Software for WordPress Startups",
"scripts": {
"dev": "npm run development",
Expand Down
10 changes: 8 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Contributors: thrivedesk
Tags: livechat, chat, help desk, chat plugin, free live chat, community, helpdesk, chatbot, knowledge base, support, help center, customer care, woocommerce, surecart, freemius, thrivedesk, zendesk, mailchimp
Requires at least: 4.9
Tested up to: 6.1.1
Stable Tag: 1.0.3
Tested up to: 6.2
Stable Tag: 1.0.4
Requires PHP: 5.5
License: GNU General Public License v2.0 or later

Expand Down Expand Up @@ -223,6 +223,12 @@ Privacy is our utmost priority, and we designed ThriveDesk in a way that aligned
- Easy setup: Setup your Shared Inbox in less than a minute.

== Changelog ==
= 1.0.4 =
- Added caching to improve response times and overall performance
- Fixed an issue where the portal area was blank after successful verification
- Fixed a bug where knowledge base docs were not being searched using the selected search provider
- Fixed an issue where style and script files were being loaded on every page

= 1.0.3 =
- Fixed an issue with an undefined variable that was causing errors in the console
- Improved error handling for API calls to ensure that errors are properly handled and reported to the user
Expand Down
61 changes: 56 additions & 5 deletions resources/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ jQuery(document).ready(($) => {
text: 'Server Error',
});
} else {
loadAssistants();
loadAssistants(apiKey);

$target.text('Verified');
$target.prop('disabled', true);
Expand All @@ -218,7 +218,8 @@ jQuery(document).ready(($) => {
$('#td-assistants').prop('disabled', false);
// add hidden class to the id td-api-verification-btn
$('#no_api_key_alert').addClass('hidden');
$('#td_post_content').removeClass('hidden');

isAllowedPortal()

Swal.fire({
icon: 'success',
Expand All @@ -236,9 +237,7 @@ jQuery(document).ready(($) => {
});
});

async function loadAssistants() {
let apiKey = $('#td_helpdesk_api_key').val().trim();

async function loadAssistants(apiKey) {
jQuery
.post(thrivedesk.ajax_url, {
action: 'thrivedesk_load_assistants',
Expand Down Expand Up @@ -293,5 +292,57 @@ jQuery(document).ready(($) => {
});
});
}

async function isAllowedPortal() {
let apiKey = $('#td_helpdesk_api_key').val().trim();
jQuery
.post(thrivedesk.ajax_url, {
action: 'thrivedesk_check_portal_access',
data: {
td_helpdesk_api_key: apiKey,
},
})
.success(function (response) {
let parsedResponse = JSON.parse(response);
let data = parsedResponse?.data;

if (data === true) {
$('#td_post_content').removeClass('hidden');
} else {
$('#portal_feature').removeClass('hidden');
}
})
.error(function () {
Swal.fire({
icon: 'error',
title: 'Error',
text: 'Something went wrong',
});
});
}

// clear cache
$('#thrivedesk_clear_cache_btn').on('click', function (e) {
jQuery
.get(thrivedesk.ajax_url, {
action: 'thrivedesk_clear_cache',
})
.success(function (response) {
Swal.fire({
icon: 'success',
title: 'Success',
text: 'Cache Cleared',
}).then((result) => {
location.reload();
});
})
.error(function () {
Swal.fire({
icon: 'error',
title: 'Error',
text: 'Something went wrong',
});
});
});
});

Loading

0 comments on commit b556abc

Please sign in to comment.