Skip to content

Commit

Permalink
Add badge on sponsor (laravelcm#113)
Browse files Browse the repository at this point in the history
* Enabled publish post only in production env

* Add sponsors list on sponsor page

* 💄 Update user avatar

* ♻️ Recatoring and fix typo error

* 🍱 Compile Assets

* ♻️ Refactoring with Pint
  • Loading branch information
mckenziearts authored May 8, 2023
1 parent 46b91ca commit e8a4534
Show file tree
Hide file tree
Showing 38 changed files with 187 additions and 59 deletions.
8 changes: 5 additions & 3 deletions app/Console/Commands/PostArticleToTelegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class PostArticleToTelegram extends Command

public function handle(AnonymousNotifiable $notifiable): void
{
if ($article = Article::nexForSharingToTelegram()) {
$notifiable->notify(new PostArticleToTelegramNotification($article));
if (app()->environment('production')) {
if ($article = Article::nexForSharingToTelegram()) {
$notifiable->notify(new PostArticleToTelegramNotification($article));

$article->markAsPublish();
$article->markAsPublish();
}
}
}
}
8 changes: 5 additions & 3 deletions app/Console/Commands/PostArticleToTwitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class PostArticleToTwitter extends Command

public function handle(AnonymousNotifiable $notifiable): void
{
if ($article = Article::nextForSharing()) {
$notifiable->notify(new PostArticleToTwitterNotification($article));
if (app()->environment('production')) {
if ($article = Article::nextForSharing()) {
$notifiable->notify(new PostArticleToTwitterNotification($article));

$article->markAsShared();
$article->markAsShared();
}
}
}
}
3 changes: 2 additions & 1 deletion app/Console/Commands/SendWelcomeMailToUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Console\Commands;

use App\Mail\Welcome;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
Expand All @@ -17,7 +18,7 @@ class SendWelcomeMailToUsers extends Command
public function handle(): void
{
foreach (User::all() as $user) {
Mail::to($user)->queue(new \App\Mail\Welcome($user));
Mail::to($user)->queue(new Welcome($user));
}
}
}
2 changes: 1 addition & 1 deletion app/Gamify/Points/DiscussionCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public function __construct(Discussion $subject)
public function payee(): User
{
// @phpstan-ignore-next-line
return $this->getSubject()->author;
return $this->getSubject()->user;
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __invoke(): View
});

$latestArticles = Cache::remember('latestArticles', now()->addHour(), function () {
return Article::with(['tags', 'user'])
return Article::with(['tags', 'user', 'user.transactions'])
->published()
->orderByDesc('sponsored_at')
->orderByDesc('published_at')
Expand All @@ -33,15 +33,15 @@ public function __invoke(): View
});

$latestThreads = Cache::remember('latestThreads', now()->addHour(), function () {
return Thread::with('user')->whereNull('solution_reply_id')
return Thread::with(['user', 'user.transactions'])->whereNull('solution_reply_id')
->whereBetween('threads.created_at', [now()->subMonths(3), now()])
->inRandomOrder()
->limit(4)
->get();
});

$latestDiscussions = Cache::remember('latestDiscussions', now()->addHour(), function () {
return Discussion::with('user')
return Discussion::with(['user', 'user.transactions'])
->recent()
->orderByViews()
->limit(3)
Expand Down
14 changes: 13 additions & 1 deletion app/Http/Controllers/SponsoringController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@

namespace App\Http\Controllers;

use App\Models\Transaction;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Cache;

class SponsoringController extends Controller
{
public function sponsors(): View
{
return view('sponsors.index');
$sponsors = Cache::remember(
'sponsors',
3600,
fn () => Transaction::with(['user', 'user.media'])
->scopes('complete')
->get(['id', 'user_id', 'metadata'])
);

return view('sponsors.index', [
'sponsors' => $sponsors
]);
}
}
2 changes: 1 addition & 1 deletion app/Http/Livewire/Articles/Browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function validSort(string $sort): bool

public function render(): View
{
$articles = Article::with(['tags', 'user'])
$articles = Article::with(['tags', 'user', 'user.transactions'])
->withCount(['views', 'reactions'])
->published()
->notPinned()
Expand Down
7 changes: 7 additions & 0 deletions app/Models/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace App\Models;

use App\Enums\TransactionStatus;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -28,6 +30,11 @@ public function user(): BelongsTo
return $this->belongsTo(User::class);
}

public function scopeComplete(Builder $query): Builder
{
return $query->where('status', TransactionStatus::COMPLETE->value);
}

public function getMetadata(string $name, string $default = ''): string | array
{
if ($this->metadata && array_key_exists($name, $this->metadata)) {
Expand Down
19 changes: 19 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Models;

use App\Enums\TransactionStatus;
use App\Traits\HasProfilePhoto;
use App\Traits\HasSettings;
use App\Traits\HasUsername;
Expand Down Expand Up @@ -104,6 +105,11 @@ class User extends Authenticatable implements MustVerifyEmail, HasMedia, Featura
protected $appends = [
'profile_photo_url',
'roles_label',
'is_sponsor',
];

protected $withCount = [
'transactions'
];

public function hasProvider(string $provider): bool
Expand Down Expand Up @@ -140,6 +146,19 @@ public function getRolesLabelAttribute(): string
return 'N/A';
}

public function getIsSponsorAttribute(): bool
{
if ($this->transactions_count > 0) {
$transaction = $this->transactions()
->where('status', TransactionStatus::COMPLETE->value)
->first();

return (bool) $transaction;
}

return false;
}

public function isAdmin(): bool
{
return $this->hasRole('admin');
Expand Down
2 changes: 2 additions & 0 deletions helpers/ModelHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ class IdeHelperThread
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Models\User $user
* @method static \Illuminate\Database\Eloquent\Builder|Transaction complete()
* @method static \Illuminate\Database\Eloquent\Builder|Transaction newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Transaction newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Transaction query()
Expand Down Expand Up @@ -804,6 +805,7 @@ class IdeHelperTransaction
* @property-read \App\Models\Enterprise|null $enterprise
* @property-read \Illuminate\Database\Eloquent\Collection<int, \LaravelFeature\Model\Feature> $features
* @property-read int|null $features_count
* @property-read bool $is_sponsor
* @property-read string|null $profile_photo_url
* @property-read string $roles_label
* @property-read \Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection<int, \Spatie\MediaLibrary\MediaCollections\Models\Media> $media
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@alpinejs/intersect": "^3.6.1",
"@headlessui/react": "^1.7.2",
"@heroicons/react": "^2.0.11",
"@ryangjchandler/alpine-tooltip": "^1.2.0",
"axios": "^0.21.1",
"canvas-confetti": "^1.4.0",
"choices.js": "^9.0.1",
Expand Down
2 changes: 1 addition & 1 deletion public/css/app.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/app.js": "/js/app.js?id=0953d0b23f555fd811dda52086298222",
"/css/app.css": "/css/app.css?id=9209b1a63d8215ae6346440a2aa9477f"
"/js/app.js": "/js/app.js?id=ba100c8f6b070c0cfac2d92eb2d9ba05",
"/css/app.css": "/css/app.css?id=7470f98fa77a0725aa692b073e05720c"
}
2 changes: 2 additions & 0 deletions resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Alpine from 'alpinejs'
import intersect from '@alpinejs/intersect'
import AlpineFloatingUI from '@awcodes/alpine-floating-ui'
import Tooltip from '@ryangjchandler/alpine-tooltip'

import NotificationsAlpinePlugin from '../../vendor/filament/notifications/dist/module.esm'
import internationalNumber from './plugins/internationalNumber'
Expand All @@ -16,6 +17,7 @@ registerHeader()
Alpine.plugin(AlpineFloatingUI)
Alpine.plugin(intersect)
Alpine.plugin(NotificationsAlpinePlugin)
Alpine.plugin(Tooltip)
Alpine.data('internationalNumber', internationalNumber)

window.Alpine = Alpine
Expand Down
8 changes: 5 additions & 3 deletions resources/views/articles/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
<div class="hidden relative lg:block lg:col-span-2">
<x-sticky-content class="divide-y divide-skin-base space-y-6">
<div>
<h4 class="text-xs text-skin-base font-medium leading-4 tracking-wide uppercase font-heading">{{ __('A propos de l’auteur') }}</h4>
<h4 class="text-xs text-skin-base font-medium leading-4 tracking-wide uppercase font-heading">
{{ __('A propos de l’auteur') }}
</h4>
<div class="mt-6 space-y-4">
<a href="{{ route('profile', $user->username) }}" class="shrink-0 block">
<div class="flex items-center">
<div>
<img class="inline-block h-9 w-9 rounded-full" src="{{ $user->profile_photo_url }}" alt="{{ $user->username }}">
<div class="shrink-0">
<x-user.avatar :user="$user" class="h-9 w-9" />
</div>
<div class="ml-3">
<p class="text-sm font-medium text-skin-inverted">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div>
<div class="flex space-x-3">
<div class="flex-shrink-0">
<img class="h-10 w-10 object-cover rounded-full" src="{{ $article->user->profile_photo_url }}" alt="{{ $article->user->name }}">
<x-user.avatar :user="$article->user" class="h-10 w-10" />
</div>
<div class="min-w-0 flex-1">
<p class="text-sm font-medium text-skin-inverted">
Expand Down
4 changes: 3 additions & 1 deletion resources/views/components/articles/card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
{{ $article->publishedAt()->isoFormat('LL') }}
</time>
<a href="{{ route('articles.show', $article) }}" class="mt-2 flex items-center justify-between group">
<h4 class="text-lg leading-6 font-semibold font-sans text-skin-inverted group-hover:text-skin-primary">{{ $article->title }}</h4>
<h4 class="text-lg leading-6 font-semibold font-sans text-skin-inverted group-hover:text-skin-primary">
{{ $article->title }}
</h4>
<svg class="ml-2.5 h-5 w-5 text-skin-base" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M13.5 6H5.25A2.25 2.25 0 003 8.25v10.5A2.25 2.25 0 005.25 21h10.5A2.25 2.25 0 0018 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25" />
</svg>
Expand Down
6 changes: 4 additions & 2 deletions resources/views/components/articles/overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
</div>
<div class="mt-2">
<a href="{{ route('articles.show', $article) }}" class="group">
<h4 class="text-lg leading-7 font-semibold font-sans text-skin-inverted group-hover:text-skin-primary">{{ $article->title }}</h4>
<h4 class="text-lg leading-7 font-semibold font-sans text-skin-inverted group-hover:text-skin-primary">
{{ $article->title }}
</h4>
</a>
<p class="mt-1 text-sm text-skin-base leading-5">
{!! $article->excerpt(130) !!}
Expand All @@ -32,7 +34,7 @@
<div class="shrink-0">
<a href="{{ route('profile', $article->user->username) }}">
<span class="sr-only">{{ $article->user->name }}</span>
<img class="h-10 w-10 object-cover rounded-full" src="{{ $article->user->profile_photo_url }}" alt="{{ $article->user->name }}">
<x-user.avatar :user="$article->user" class="h-10 w-10" />
</a>
</div>
<div class="ml-3">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/discussions/overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="mt-3 sm:flex sm:justify-between">
<div class="flex items-center text-sm font-sans text-skin-muted">
<a class="shrink-0" href="{{ route('profile', $discussion->user->username) }}">
<img class="h-6 w-6 object-cover rounded-full" src="{{ $discussion->user->profile_photo_url }}" alt="{{ $discussion->user->name }}">
<x-user.avatar :user="$discussion->user" class="h-6 w-6" span="-right-1 -top-1 ring-1 h-4 w-4" />
</a>
<span class="ml-2 pr-1">{{ __('Posté par') }}</span>
<div class="flex items-center space-x-1" wire:ignore>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/components/discussions/summary.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
<div class="mt-3 flex justify-between">
<div class="flex items-center text-sm font-sans text-skin-muted">
<a class="shrink-0" href="{{ route('profile', $discussion->user->username) }}">
<img class="h-6 w-6 object-cover rounded-full" src="{{ $discussion->user->profile_photo_url }}" alt="{{ $discussion->user->name }}">
<x-user.avatar :user="$discussion->user" class="h-6 w-6" />
</a>
<span class="ml-2 pr-1">Posté par</span>
<span class="ml-2 pr-1">{{ __('Posté par') }}</span>
<div class="flex items-center space-x-1">
<a href="{{ route('profile', $discussion->user->username) }}" class="text-skin-inverted hover:underline">
{{ $discussion->user->name }}
Expand Down
10 changes: 5 additions & 5 deletions resources/views/components/dropdown-profile.blade.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div @keydown.escape.stop="open = false;" @click.outside="open = false;" class="ml-4 relative shrink-0">
<div>
<button type="button" class="bg-skin-menu rounded-full flex text-sm focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500" id="user-menu-button" x-ref="button" @click="open =! open" aria-expanded="false" aria-haspopup="true" x-bind:aria-expanded="open.toString()">
<span class="sr-only">Open user menu</span>
<img class="h-8 w-8 object-cover rounded-full" src="{{ Auth::user()->profile_photo_url }}" alt="{{ Auth::user()->name }}">
<span class="sr-only">{{ __('Ouverture du menu') }}</span>
<x-user.avatar :user="Auth::user()" class="h-8 w-8" />
</button>
</div>

Expand Down Expand Up @@ -49,7 +49,7 @@ class="origin-top-right absolute right-0 mt-2 w-60 rounded-md shadow-lg py-1 bg-
<svg class="mr-1.5 h-2 w-2 text-orange-400" fill="currentColor" viewBox="0 0 8 8">
<circle cx="4" cy="4" r="3" />
</svg>
Off
{{ __('Off') }}
</span>
</div>
<div class="py-1 5">
Expand All @@ -72,7 +72,7 @@ class="origin-top-right absolute right-0 mt-2 w-60 rounded-md shadow-lg py-1 bg-
</div>
<div class="my-2 px-3 py-2.5 border border-skin-base rounded-md">
<h6 class="inline-flex items-center text-sm leading-5 font-medium text-skin-inverted-muted">
Profil incomplet!
{{ __('Profil incomplet!') }}
<svg class="ml-1.5 text-sky-500 w-4 h-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path fill-rule="evenodd" d="M8.603 3.799A4.49 4.49 0 0112 2.25c1.357 0 2.573.6 3.397 1.549a4.49 4.49 0 013.498 1.307 4.491 4.491 0 011.307 3.497A4.49 4.49 0 0121.75 12a4.49 4.49 0 01-1.549 3.397 4.491 4.491 0 01-1.307 3.497 4.491 4.491 0 01-3.497 1.307A4.49 4.49 0 0112 21.75a4.49 4.49 0 01-3.397-1.549 4.49 4.49 0 01-3.498-1.306 4.491 4.491 0 01-1.307-3.498A4.49 4.49 0 012.25 12c0-1.357.6-2.573 1.549-3.397a4.49 4.49 0 011.307-3.497 4.49 4.49 0 013.497-1.307zm7.007 6.387a.75.75 0 10-1.22-.872l-3.236 4.53L9.53 12.22a.75.75 0 00-1.06 1.06l2.25 2.25a.75.75 0 001.14-.094l3.75-5.25z" clip-rule="evenodd" />
</svg>
Expand All @@ -81,7 +81,7 @@ class="origin-top-right absolute right-0 mt-2 w-60 rounded-md shadow-lg py-1 bg-
{{ __('Nous avons besoin de plus d\'informations pour vous mettre en relation avec les entreprises.') }}
</p>
<a href="#" class="inline-block rounded-md mt-3 w-full border border-skin-base px-1.5 py-2 text-center text-sm leading-4 font-medium text-skin-base hover:text-skin-inverted-muted">
Compléter mon profil
{{ __('Compléter mon profil') }}
</a>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/forum/thread-author.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="bg-skin-card rounded-lg shadow">
<div class="w-full flex items-center justify-between pt-4 px-4 space-x-3">
<img class="w-8 h-8 object-cover bg-skin-card-gray rounded-full shrink-0" src="{{ $author->profile_photo_url }}" alt="{{ $author->name }}">
<x-user.avatar :user="$author" class="h-8 w-8" />
<div class="flex-1 truncate">
<div class="flex items-center space-x-3">
<a href="{{ route('profile', $author->username) }}" class="text-skin-inverted text-sm font-medium truncate">{{ $author->name }}</a>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/components/forum/thread-overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="lg:flex lg:space-x-3">
<div class="flex-1 flex items-center space-x-3">
<div class="shrink-0">
<img class="h-8 w-8 object-cover rounded-full" src="{{ $thread->user->profile_photo_url }}" alt="{{ $thread->user->name }}">
<x-user.avatar :user="$thread->user" class="h-8 w-8" />
</div>
<div class="min-w-0 flex-1">
<p class="text-sm font-medium text-skin-inverted">
Expand Down
Loading

0 comments on commit e8a4534

Please sign in to comment.