Skip to content

Commit

Permalink
move files from main repo
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtorres committed Oct 4, 2023
1 parent 230064a commit 7ad8e46
Show file tree
Hide file tree
Showing 50 changed files with 956 additions and 0 deletions.
Empty file added src/Config/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions src/Config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'name' => 'Reviews',
];
Empty file added src/Console/.gitkeep
Empty file.
Empty file.
41 changes: 41 additions & 0 deletions src/Database/Migrations/2022_07_29_183304_create_reviews_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use App\Models\Language;
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateReviewsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('reviews', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(User::class, 'user_id')->index();
$table->nullableMorphs('reviewable');
$table->text('body');
$table->integer('visibility')->default(1);
$table->foreignIdFor(Language::class, 'language_id')->index()->default(1);
$table->boolean('received_product_free')->default(false);
$table->boolean('recommend')->default(false);
$table->boolean('commentable')->default(true);
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('reviews');
}
}
Empty file added src/Database/Seeders/.gitkeep
Empty file.
29 changes: 29 additions & 0 deletions src/Database/Seeders/ReviewTableSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Modules\Reviews\Database\Seeders;

use Illuminate\Database\Seeder;
use Modules\Reviews\Models\Review;
use Modules\Social\Models\Post;

class ReviewTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Review::truncate();

// Reviews
Review::factory(15)->create();

// Review Comments
Post::factory(15)->create([
'postable_id' => Review::all()->random()->id,
'postable_type' => Review::class,
]);
}
}
21 changes: 21 additions & 0 deletions src/Database/Seeders/ReviewsDatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Modules\Reviews\Database\Seeders;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;

class ReviewsDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();

$this->call(ReviewTableSeeder::class);
}
}
Empty file added src/Database/factories/.gitkeep
Empty file.
36 changes: 36 additions & 0 deletions src/Database/factories/ReviewFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Modules\Reviews\Database\factories;

use App\Models\Team;
use Illuminate\Database\Eloquent\Factories\Factory;
use Modules\Reviews\Models\Review;

class ReviewFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Review::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$team = Team::all()->random()->load('users');

return [
'user_id' => $team->users->random()->id,
'reviewable_id' => $team->id,
'reviewable_type' => $team::class,
'body' => $this->faker->paragraph(4),
'created_at' => now(),
'updated_at' => now(),
];
}
}
Empty file added src/Emails/.gitkeep
Empty file.
Empty file added src/Events/.gitkeep
Empty file.
Empty file added src/Http/Controllers/.gitkeep
Empty file.
84 changes: 84 additions & 0 deletions src/Http/Controllers/ReviewsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace Modules\Reviews\Http\Controllers;

use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

class ReviewsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Renderable
*/
public function index()
{
return view('reviews::index');
}

/**
* Show the form for creating a new resource.
*
* @return Renderable
*/
public function create()
{
return view('reviews::create');
}

/**
* Store a newly created resource in storage.
*
* @return Renderable
*/
public function store(Request $request)
{
//
}

/**
* Show the specified resource.
*
* @param int $id
* @return Renderable
*/
public function show($id)
{
return view('reviews::show');
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Renderable
*/
public function edit($id)
{
return view('reviews::edit');
}

/**
* Update the specified resource in storage.
*
* @param int $id
* @return Renderable
*/
public function update(Request $request, $id)
{
//
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Renderable
*/
public function destroy($id)
{
//
}
}
129 changes: 129 additions & 0 deletions src/Http/Livewire/CreateReviewModal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

namespace Modules\Reviews\Http\Livewire;

use App\Models\Language;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Livewire\Component;
use Modules\Reviews\Models\Review;
use OmniaDigital\OmniaLibrary\Livewire\WithModal;
use OmniaDigital\CatalystCore\Facades\Translate;

class CreateReviewModal extends Component implements HasForms
{
use WithModal, InteractsWithForms;

public $model;

public Review|null $review = null;

public $body;
public $visibility;
public $language_id;
public $commentable;
public $received_product_free;
public $recommend;

protected $listeners = ['openReviewModal'];

public function mount($model)
{
$this->model = $model;
}

public function openReviewModal()
{
if ($this->model->reviewedBy(auth()->user())) {
$this->review = $this->model->getCurrentUserReview();

$this->form->fill([
'body' => $this->review->body,
'visibility' => $this->review->visibility,
'language_id' => $this->review->language_id,
'commentable' => $this->review->commentable,
'received_product_free' => $this->review->received_product_free,
'recommend' => $this->review->recommend,
]);
} else {
$this->form->fill();
}

$this->dispatch('review-modal-' . $this->model->id, type: 'open');
}

public function createReview()
{
if ($this->model->reviewedBy(auth()->user())) {
$this->review->update(
$this->form->getState()
);

$this->dispatch('reviewUpdated')->to('reviews::review-card');
$this->dispatch('notify', message: Translate::get('Review updated'), type: 'success');
} else {
$this->review = $this->model->reviews()->create(
array_merge(['user_id' => auth()->id()], $this->form->getState())
);

$this->dispatch('notify', message: Translate::get('Review created'), type: 'success');
}

$this->dispatch('updateReviews', review: $this->review);
$this->closeModal('review-modal-' . $this->model->id);
$this->reset('body', 'visibility', 'language_id', 'commentable', 'received_product_free', 'recommend');
}

public function removeReview()
{
if ($this->model->reviewedBy(auth()->user())) {
$this->review->delete();

$this->dispatch('notify', message: Translate::get('Review removed'), type: 'success');

$this->dispatch('updateReviews');
$this->closeModal('review-modal-' . $this->model->id);
$this->reset('body', 'visibility', 'language_id', 'commentable', 'received_product_free', 'recommend');
}
}

public function render()
{
return view('reviews::livewire.create-review-modal');
}

protected function getFormSchema(): array
{
return [
Textarea::make('body')->required(),
Select::make('visibility')
->options([
0 => 'Public',
1 => 'Friends Only',
])
->default(0)
->disablePlaceholderSelection()
->required(),
Select::make('language_id')
->label('Language')
->options(Language::pluck('name', 'id'))
->default(1)
->disablePlaceholderSelection()
->required(),
Checkbox::make('commentable')
->default(1)
->label('Allow Comments'),
Checkbox::make('received_product_free')
->default(0)
->label('Check this box if you joined for free'),
Radio::make('recommend')
->label(Translate::get('Do you recommend this Team?'))
->boolean()
->required(),
];
}
}
24 changes: 24 additions & 0 deletions src/Http/Livewire/ReviewCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Modules\Reviews\Http\Livewire;

use Livewire\Component;
use Modules\Reviews\Models\Review;

class ReviewCard extends Component
{
public $review;

protected $listeners = ['reviewUpdated' => '$refresh'];

public function mount(Review $review)
{
$this->review = $review;
$this->review->load('user');
}

public function render()
{
return view('reviews::livewire.review-card');
}
}
Loading

0 comments on commit 7ad8e46

Please sign in to comment.