Skip to content

Commit

Permalink
Merge pull request #79 from andrewdwallo/fix/socialite
Browse files Browse the repository at this point in the history
fix: socialite
  • Loading branch information
andrewdwallo authored Aug 25, 2023
2 parents 4165ea3 + 6b7b412 commit 74c8f28
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 147 deletions.
89 changes: 47 additions & 42 deletions resources/views/components/connected-account.blade.php
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
@props(['provider', 'createdAt' => null])

@php
use Wallo\FilamentCompanies\Providers;
$providers = [
'facebook' => ['method' => 'hasFacebook'],
'twitter' => ['method' => 'hasTwitterOAuth1'],
'twitter' => ['method' => 'hasTwitterOAuth2'],
'github' => ['method' => 'hasGithub'],
'google' => ['method' => 'hasGoogle'],
'linkedin' => ['method' => 'hasLinkedIn'],
'gitlab' => ['method' => 'hasGitlab'],
'bitbucket' => ['method' => 'hasBitbucket'],
Providers::github() => ['method' => Providers::hasGithub(), 'name' => 'GitHub'],
Providers::gitlab() => ['method' => Providers::hasGitlab(), 'name' => 'GitLab'],
Providers::google() => ['method' => Providers::hasGoogle(), 'name' => 'Google'],
Providers::facebook() => ['method' => Providers::hasFacebook(), 'name' => 'Facebook'],
Providers::linkedin() => ['method' => Providers::hasLinkedIn(), 'name' => 'LinkedIn'],
Providers::bitbucket() => ['method' => Providers::hasBitbucket(), 'name' => 'Bitbucket'],
Providers::twitter() => ['method' => Providers::hasTwitter(), 'name' => 'Twitter'],
Providers::twitterOAuth2() => ['method' => Providers::hasTwitterOAuth2(), 'name' => 'Twitter'],
];
@endphp
@foreach($providers as $icon => $provider)
@if(Wallo\FilamentCompanies\Providers::{$provider['method']}())
<div class="filament-companies-connected-account">
<div class="filament-companies-connected-account-container flex items-center justify-between">
<div class="filament-companies-connected-account-details flex items-center gap-x-2">
<div class="filament-companies-connected-account-icon h-8 w-8">
@component("filament-companies::components.socialite-icons.{$icon}") @endcomponent
</div>
$icon = $provider === Providers::twitterOAuth2() ? Providers::twitter() : $provider;
$name = $providers[$provider]['name'];
@endphp

<div class="filament-companies-connected-account-info font-semibold">
<div class="filament-companies-connected-account-name text-sm text-gray-800 dark:text-gray-200">
{{ __(ucfirst($icon)) }}
</div>
@if($providers[$provider]['method'])
<div class="filament-companies-connected-account">
<div class="filament-companies-connected-account-container flex items-center justify-between">
<div class="filament-companies-connected-account-details flex items-center gap-x-2">
<div class="filament-companies-connected-account-icon h-8 w-8">
@component("filament-companies::components.socialite-icons.{$icon}") @endcomponent
</div>

@if (!empty($createdAt))
<div class="filament-companies-connected-account-connected text-xs text-primary-700 dark:text-primary-500">
{{ __('filament-companies::default.labels.connected') }}
<div class="filament-companies-connected-account-connected-date text-xs text-gray-600 dark:text-gray-300">
{{ $createdAt }}
</div>
</div>
@else
<div class="filament-companies-connected-account-not-connected text-xs text-gray-400">
{{ __('filament-companies::default.labels.not_connected') }}
</div>
@endif
<div class="filament-companies-connected-account-info font-semibold">
<div class="filament-companies-connected-account-name text-sm text-gray-800 dark:text-gray-200">
{{ __($name) }}
</div>
</div>

<div>
{{ $action }}
@if (!empty($createdAt))
<div
class="filament-companies-connected-account-connected text-xs text-primary-700 dark:text-primary-500">
{{ __('filament-companies::default.labels.connected') }}
<div
class="filament-companies-connected-account-connected-date text-xs text-gray-600 dark:text-gray-300">
{{ $createdAt }}
</div>
</div>
@else
<div class="filament-companies-connected-account-not-connected text-xs text-gray-400">
{{ __('filament-companies::default.labels.not_connected') }}
</div>
@endif
</div>
</div>

@error($icon.'_connect_error')
<div class="filament-companies-connected-account-error text-sm font-semibold text-danger-500 px-3 mt-2">
{{ $message }}
<div>
{{ $action }}
</div>
@enderror
</div>
@endif
@endforeach

@error($provider.'_connect_error')
<div class="filament-companies-connected-account-error text-sm font-semibold text-danger-500 px-3 mt-2">
{{ $message }}
</div>
@enderror
</div>
@endif
40 changes: 22 additions & 18 deletions resources/views/components/socialite.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,30 @@
<hr class="w-full ml-2">
</div>

<div class="filament-companies-socialite-button-container mt-6 flex flex-wrap items-center justify-center gap-6">
@php
$providers = [
'facebook' => ['method' => 'hasFacebook'],
'twitter' => ['method' => 'hasTwitterOAuth1'],
'twitter' => ['method' => 'hasTwitterOAuth2'],
'github' => ['method' => 'hasGithub'],
'google' => ['method' => 'hasGoogle'],
'linkedin' => ['method' => 'hasLinkedIn'],
'gitlab' => ['method' => 'hasGitlab'],
'bitbucket' => ['method' => 'hasBitbucket'],
// Add other providers if needed
];
@endphp
@php
use Wallo\FilamentCompanies\Providers;
$providers = [
Providers::github() => ['method' => Providers::hasGithub(), 'name' => 'GitHub'],
Providers::gitlab() => ['method' => Providers::hasGitlab(), 'name' => 'GitLab'],
Providers::google() => ['method' => Providers::hasGoogle(), 'name' => 'Google'],
Providers::facebook() => ['method' => Providers::hasFacebook(), 'name' => 'Facebook'],
Providers::linkedin() => ['method' => Providers::hasLinkedIn(), 'name' => 'LinkedIn'],
Providers::bitbucket() => ['method' => Providers::hasBitbucket(), 'name' => 'Bitbucket'],
Providers::twitter() => ['method' => Providers::hasTwitter(), 'name' => 'Twitter'],
Providers::twitterOAuth2() => ['method' => Providers::hasTwitterOAuth2(), 'name' => 'Twitter'],
];
@endphp

@foreach ($providers as $icon => $provider)
@if (Wallo\FilamentCompanies\Providers::{$provider['method']}())
<a href="{{ route('filament.company.oauth.redirect', ['provider' => $icon]) }}"
<div class="filament-companies-socialite-button-container mt-6 flex flex-wrap items-center justify-center gap-6">
@foreach ($providers as $iconKey => $provider)
@php
$icon = $iconKey === Providers::twitterOAuth2() ? Providers::twitter() : $iconKey;
@endphp
@if ($provider['method'])
<a href="{{ route('filament.company.oauth.redirect', ['provider' => $iconKey]) }}"
class="filament-companies-socialite-buttons inline-flex rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 dark:focus:border-primary-500 py-2 px-4 shadow-sm hover:bg-gray-50 dark:hover:bg-gray-600">
<span class="sr-only">{{ ucfirst($icon) }}</span>
<span class="sr-only">{{ $provider['name'] }}</span>
<div class="h-6 w-6">
@component("filament-companies::components.socialite-icons.{$icon}")@endcomponent
</div>
Expand Down
1 change: 0 additions & 1 deletion resources/views/profile/connected-accounts-form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<div class="grid gap-y-6">
@foreach ($this->providers as $provider)
@php
$account = null;
$account = $this->accounts->where('provider', $provider)->first();
@endphp

Expand Down
35 changes: 10 additions & 25 deletions src/Providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,70 @@

namespace Wallo\FilamentCompanies;

use BadMethodCallException;
use Illuminate\Support\Str;

class Providers
{
/**
* Determine if the application has support for the Bitbucket provider.
*/
public static function hasBitbucket(): bool
{
return Socialite::hasBitbucket();
return Socialite::$supportedSocialiteProviders['bitbucket'];
}

/**
* Determine if the application has support for the Facebook provider.
*/
public static function hasFacebook(): bool
{
return Socialite::hasFacebook();
return Socialite::$supportedSocialiteProviders['facebook'];
}

/**
* Determine if the application has support for the GitLab provider.
*/
public static function hasGitlab(): bool
{
return Socialite::hasGitlab();
return Socialite::$supportedSocialiteProviders['gitlab'];
}

/**
* Determine if the application has support for the GitHub provider.
*/
public static function hasGithub(): bool
{
return Socialite::hasGithub();
return Socialite::$supportedSocialiteProviders['github'];
}

/**
* Determine if the application has support for the Google provider.
*/
public static function hasGoogle(): bool
{
return Socialite::hasGoogle();
return Socialite::$supportedSocialiteProviders['google'];
}

/**
* Determine if the application has support for the LinkedIn provider.
*/
public static function hasLinkedIn(): bool
{
return Socialite::hasLinkedIn();
return Socialite::$supportedSocialiteProviders['linkedin'];
}

/**
* Determine if the application has support for the Twitter OAuth 1.0 provider.
*/
public static function hasTwitterOAuth1(): bool
public static function hasTwitter(): bool
{
return Socialite::hasTwitter();
return Socialite::$supportedSocialiteProviders['twitter'];
}

/**
* Determine if the application has support for the Twitter OAuth 2.0 provider.
*/
public static function hasTwitterOAuth2(): bool
{
return Socialite::hasTwitterOAuth2();
return Socialite::$supportedSocialiteProviders['twitter-oauth-2'];
}

/**
Expand Down Expand Up @@ -122,7 +119,7 @@ public static function linkedin(): string
/**
* Enable the Twitter OAuth 1.0 provider.
*/
public static function twitterOAuth1(): string
public static function twitter(): string
{
return 'twitter';
}
Expand All @@ -134,16 +131,4 @@ public static function twitterOAuth2(): string
{
return 'twitter-oauth-2';
}

/**
* Throw a bad method call exception for the given method.
*
* @throws BadMethodCallException
*/
protected static function throwBadMethodCallException(string $method): void
{
throw new BadMethodCallException(sprintf(
'Call to undefined method %s::%s()', static::class, $method
));
}
}
Loading

0 comments on commit 74c8f28

Please sign in to comment.