Skip to content

Commit

Permalink
add review / refactor regional congfiguration / various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerrialn committed Feb 7, 2024
1 parent cdbd2cf commit 127e678
Show file tree
Hide file tree
Showing 50 changed files with 1,172 additions and 369 deletions.
14 changes: 14 additions & 0 deletions assets/TimezoneService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from "axios";

export default class TimezoneService {
constructor() {
this.timezone = null;
}

async configureTimezone() {
this.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
axios.post('https://localhost/set/browser/timezone', {
timezone: this.timezone
});
}
}
4 changes: 4 additions & 0 deletions assets/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ import 'chartjs-adapter-date-fns';

// any CSS you import will output into a single css file (app.css in this case)
import './styles/app.scss';
import TimezoneService from './TimezoneService'


const timezoneService = new TimezoneService();
timezoneService.configureTimezone();

document.addEventListener('turbo:load', function (e) {
let tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
let tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
Expand Down
64 changes: 64 additions & 0 deletions assets/controllers/star-rating-hover_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { Controller } from '@hotwired/stimulus';

export default class extends Controller {
static targets = ['star']

connect() {
this.stars = this.starTargets;
this.currentRating = this.getRating();
}
handleStarHover = (event) => {
const starIndex = this.stars.indexOf(event.target);
const currentRating = this.currentRating;

this.dispatchEvent('hover', { starIndex, currentRating });
};

getRating() {
// Get the current rating from the data-action attribute
const dataAction = this.element.dataset.action.split('|');
const actionType = dataAction[0];
const actionData = dataAction[1];

if (actionType === 'prevent') {
// Extract the rating from the data-action-name attribute
const rating = actionData.split('(')[1].split(')')[0];
return Number(rating);
}
}

hover(event) {
const starIndex = event.detail.starIndex;
const currentRating = event.detail.currentRating;

if (starIndex < currentRating) {
// Increase the current rating
this.currentRating++;
this.updateStarsColor();
} else if (starIndex === currentRating) {
// Highlight the current rating
this.highlightStar(starIndex);
} else {
// Decrement the current rating
this.currentRating--;
this.updateStarsColor();
}
}

updateStarsColor() {
for (let i = 0; i < this.currentRating; i++) {
this.stars[i].classList.add('bi-star-fill');
this.stars[i].classList.remove('bi-star');
}

for (let i = this.currentRating; i < this.stars.length; i++) {
this.stars[i].classList.add('bi-star');
this.stars[i].classList.remove('bi-star-fill');
}
}

highlightStar(index) {
this.stars[index].classList.add('bi-star-fill');
this.stars[index].classList.remove('bi-star');
}
}
14 changes: 0 additions & 14 deletions assets/controllers/timezone_controller.js

This file was deleted.

29 changes: 12 additions & 17 deletions assets/styles/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ $table-th-font-weight: 500 !default;
// Buttons + Forms

$input-btn-padding-y: .75rem !default;
$btn-border-radius: 0.25rem !default;
$btn-border-radius: 0 !default;
$input-btn-padding-x: 1rem !default;
$input-btn-font-size: $font-size-sm !default;

Expand All @@ -97,7 +97,7 @@ $input-box-shadow: 0 !default;
$input-focus-border-color: $gray-400 !default;
$input-focus-color: $black;
$input-placeholder-color: $black;
$input-focus-box-shadow: 0 !default;
$input-focus-box-shadow: 0 !default;
$input-group-addon-bg: $gray-100 !default;

$border-width: 1px !default;
Expand All @@ -108,34 +108,26 @@ $border-width: 1px !default;
$form-select-box-shadow: 0 !default;
$form-select-focus-box-shadow: 0 !default;

// Navs
$nav-link-color: $body-color !default;
$nav-link-disabled-color: $secondary !default;
$nav-link-hover-color: $dark !default;

// Navs
.nav .nav-link:hover, .nav .nav-link:focus {
background-color: $light;
}

$nav-link-color: $black !default;
$nav-link-disabled-color: $secondary !default;
$nav-link-hover-color: $dark !default;
$nav-tabs-border-radius: 1rem !default;
$nav-tabs-link-active-color: $primary !default;

$nav-tabs-link-active-color: $gray-300 !default;
$nav-link-padding-x: 1rem !default;
$nav-link-padding-y: 0.75rem !default;
;
$nav-tab: 0.75rem !default;
$nav-pills-border-radius: 0.25rem !default;
$nav-tab: 0 !default;
$nav-pills-border-radius: 0 !default;

// Navbar

$navbar-padding-y: .85rem !default;

$navbar-nav-link-padding-x: .75rem !default;

$navbar-dark-color: $white !default;
$navbar-dark-hover-color: $white !default;
$navbar-dark-active-color: $white !default;

$navbar-light-color: $black !default;
$navbar-light-hover-color: $black !default;
$navbar-light-active-color: $black !default;
Expand Down Expand Up @@ -184,6 +176,9 @@ $card-inner-border-radius: 0 !default;

$toast-header-color: $headings-color !default;

// Alerts
$alert-border-radius: 0 !default;

// Modals

$modal-content-border-color: $gray-300 !default;
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"name": "eventpoints/eventpoint.app",
"description": "event orgnising web application",
"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
Expand Down
6 changes: 4 additions & 2 deletions config/packages/twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

declare(strict_types=1);

use App\Model\BrowserRegionalData;
use App\Model\RegionalConfiguration;
use App\Service\ApplicationTimeService\ApplicationTimeService;
use App\Service\RegionalSettingsService\RegionalSettingsService;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('twig', [
'default_path' => '%kernel.project_dir%/templates',
'globals' => [
'regional' => service(RegionalSettingsService::class),
'regional' => service(RegionalConfiguration::class),
'browser_timezone' => service(BrowserRegionalData::class),
'supported_locales' => explode(',', (string) $_ENV['SUPPORTED_LOCALES']),
'app_time' => service(ApplicationTimeService::class),
'date_pattern' => 'dd MM yy',
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Controller/Event/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(
private readonly TranslatorInterface $translator,
private readonly EventGroupRepository $eventGroupRepository,
private readonly EventEmailInvitationRepository $eventEmailInvitationRepository,
private readonly EventInvitationRepository $eventInvitationRepository
private readonly EventInvitationRepository $eventInvitationRepository,
) {
}

Expand Down
60 changes: 60 additions & 0 deletions src/Controller/Controller/RegionalConfigurationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace App\Controller\Controller;

use App\Entity\User;
use App\Form\Filter\RegionFilterType;
use App\Model\RegionalConfiguration;
use App\Repository\UserRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\CurrentUser;

#[Route('/region')]
class RegionalConfigurationController extends AbstractController
{
public function __construct(
private readonly RegionalConfiguration $regionalSetting,
private readonly UserRepository $userRepository,
) {
}

#[Route(path: '/', name: '_app_regional_settings', methods: ['GET', 'POST'])]
public function index(Request $request, #[CurrentUser] null|User $user): Response
{
$session = $request->getSession();
$regionForm = $this->createForm(RegionFilterType::class, $this->regionalSetting, [
'request' => $request,
]);
$regionForm->handleRequest($request);
if ($regionForm->isSubmitted() && $regionForm->isValid()) {
if ($user instanceof User) {
$user->setLocale($regionForm->get('locale')->getData());
$user->setCurrency($regionForm->get('currency')->getData());
$user->setCountry($regionForm->get('region')->getData());
$user->setTimezone($regionForm->get('timezone')->getData());
$this->userRepository->save(entity: $user, flush: true);
}

$this->regionalSetting->setLocale($regionForm->get('locale')->getData());
$this->regionalSetting->setCurrency($regionForm->get('currency')->getData());
$this->regionalSetting->setRegion($regionForm->get('region')->getData());
$this->regionalSetting->setTimezone($regionForm->get('timezone')->getData());

$session->set('_locale', $regionForm->get('locale')->getData());
$session->set('_currency', $regionForm->get('currency')->getData());
$session->set('_region', $regionForm->get('region')->getData());
$session->set('_timezone', $regionForm->get('timezone')->getData());

return $this->redirectToRoute('events');
}

return $this->render('regional-settings/form.html.twig', [
'regionForm' => $regionForm->createView(),
]);
}
}
51 changes: 0 additions & 51 deletions src/Controller/Controller/RegionalSettingsController.php

This file was deleted.

25 changes: 2 additions & 23 deletions src/Controller/Controller/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
use App\Security\CustomAuthenticator;
use App\Security\EmailVerifier;
use App\Service\AvatarService\AvatarService;
use App\Service\EmailEventService\EmailEventService;
use App\Service\EmailService\EmailToUserConnectorService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mime\Address;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\UserAuthenticatorInterface;
Expand All @@ -28,10 +24,8 @@
class RegistrationController extends AbstractController
{
public function __construct(
private readonly EmailVerifier $emailVerifier,
private readonly AvatarService $avatarService,
private readonly EmailEventService $emailEventService,
private readonly EmailToUserConnectorService $emailToUserConnectorService,
private readonly AvatarService $avatarService,
private readonly EmailVerifier $emailVerifier
) {
}

Expand All @@ -56,20 +50,6 @@ public function register(Request $request, UserPasswordHasherInterface $userPass
$entityManager->persist($user);
$entityManager->flush();

$this->emailEventService->process(user: $user);
$this->emailToUserConnectorService->connect(user: $user);

// generate a signed url and email it to the user
$this->emailVerifier->sendEmailConfirmation(
'app_verify_email',
$user,
(new TemplatedEmail())
->from(new Address('[email protected]', 'Event Point'))
->to($user->getEmail())
->subject('Please Confirm your Email')
->htmlTemplate('email/confirmation_email.html.twig')
);

return $userAuthenticator->authenticateUser(
$user,
$authenticator,
Expand Down Expand Up @@ -102,7 +82,6 @@ public function verifyUserEmail(Request $request, TranslatorInterface $translato
$this->emailVerifier->handleEmailConfirmation($request, $user);
} catch (VerifyEmailExceptionInterface $exception) {
$this->addFlash('verify_email_error', $translator->trans($exception->getReason(), [], 'VerifyEmailBundle'));

return $this->redirectToRoute('app_register');
}

Expand Down
Loading

0 comments on commit 127e678

Please sign in to comment.