Skip to content

Commit

Permalink
Merge pull request #693 from City-of-Helsinki/UHF-8988
Browse files Browse the repository at this point in the history
UHF-8988 user inquiry popup
  • Loading branch information
rpnykanen authored Feb 20, 2024
2 parents 0729ff9 + b0d4b7e commit 323adaa
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
29 changes: 27 additions & 2 deletions assets/js/chat_leijuke.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
return new GenesysAdapter;
}
if (chatSelection.indexOf('user_inquiry') != -1) {
return new UserInquiryAdapter;
if (UserInquiryAdapter.idScheduled()) {
return new UserInquiryAdapter;
}
}
console.warn(`No adapter found for ${chatSelection}!`);
}
Expand Down Expand Up @@ -91,7 +93,7 @@
*/
class UserInquiryAdapter {
constructor() {
this.requiredCookies = ['chat'];
this.requiredCookies = ['statistics'];
this.bot = false;
this.persist = false;
this.hasButton = false;
Expand All @@ -100,6 +102,29 @@
open(callback) {}
onClosed(callback) {}
onLoaded(callback) {}

// Return true or false based on hardcoded dates or value in localstorage.
static idScheduled() {
const now = new Date();

const dates = [
{start: '2024-02-26', end: '2024-03-01'},
{start: '2024-03-04', end: '2024-03-08'},
]

// Run the code below in browser to activate the popup for a minute
// localStorage.setItem('user_inquiry_debug', `{"start": "${new Date((Date.now()-60000)).toString()}", "end": "${new Date((Date.now()+60000))}"}`);
const debug = localStorage.getItem('user_inquiry_debug');
if (debug) {
dates.push(JSON.parse(debug));
}

const date = dates.find((object)=>{
return now >= new Date(object.start) && now < new Date(object.end);
});

return !!date;
}
}

class Leijuke {
Expand Down
62 changes: 62 additions & 0 deletions helfi_platform_config.install
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,65 @@ function helfi_platform_config_update_9304() : void {
$config->set('links', $links)
->save();
}

/**
* Enable leijuke-block which contains the user inquiry -popup.
*/
function helfi_platform_config_update_9305() : void {

if (!\Drupal::moduleHandler()->moduleExists('helfi_api_base')) {
return;
}

$environment_resolver = \Drupal::service('helfi_api_base.environment_resolver');
try {
$environment_resolver->getActiveProject();
}
catch (Exception $exception) {
// No active project found, stop execution.
return;
}

$block_installer = Drupal::service('helfi_platform_config.helper.block_installer');
$theme_handler = \Drupal::service('theme_handler');
if (!str_starts_with($theme_handler->getDefault(), 'hdbt')) {
return;
}

$theme = $theme_handler->getDefault() === 'hdbt_subtheme' ? 'hdbt_subtheme' : 'hdbt';

$block = [
'id' => 'hdbt_subtheme_user_inquiry',
'plugin' => 'chat_leijuke',
'provider' => 'helfi_platform_config',
'settings' => [
'label' => 'User inquiry',
'label_display' => FALSE,
'chat_title' => '',
'chat_selection' => 'user_inquiry',
],
'visibility' => [
'language' => [
'id' => 'language',
'context_mapping' => [
'language' => '@language.current_language_context:language_interface',
],
'langcodes' => ['fi' => 'fi', 'en' => 'en', 'sv' => 'sv'],
],
'user_role' => [
'id' => 'user_role',
'roles' => ['anonymous' => 'anonymous'],
'context_mapping' => ['user' => '@user.current_user_context:current_user'],
],
],
];

$variations = [
[
'theme' => $theme,
'region' => 'attachments',
],
];

$block_installer->install($block, $variations);
}
2 changes: 1 addition & 1 deletion helfi_platform_config.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ genesys_auth_redirect:
- core/drupalSettings

chat_leijuke:
version: 1.0.x
version: 1.0.1
header: true
js:
assets/js/chat_leijuke.js: {}
Expand Down

0 comments on commit 323adaa

Please sign in to comment.