-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor Demo module and enhance with new sections and seeding #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7666aa8
feat: refactor demo module structure and update related configurations
roble 05228b0
feat: add database seeding task for Demo module
roble cf014a3
Merge pull request #4 from saucebase-dev/feat/internachi-modular
roble 6e93b7c
feat: implement new sections for demo module including features, test…
roble 8bdf62b
feat: add ModulesSection component and integrate it into the Index page
roble d31c25c
feat: enhance HeroSection and ModulesSection with improved layout and…
roble 0453d06
feat: update navigation for Stripe Integration and clean up unused se…
roble c0b34e3
feat: update copyright year in LICENSE and enhance FaqSection tech st…
roble dffcf96
Merge pull request #5 from saucebase-dev/feat/internachi-modular
roble bd75dfa
feat: implement DatabaseSeeder and enhance DatabaseSeederTest for mod…
roble e030378
feat: add dashboard images and update FeaturesSection with new image …
roble 4fbb170
feat: refactor sections and update feature descriptions for improved …
roble 8e9c65d
fix(ci): trim demo module test dependencies
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| <?php | ||
|
|
||
| namespace Modules\Demo\Database\Seeders; | ||
|
|
||
| use Illuminate\Database\Seeder; | ||
|
|
||
| class DatabaseSeeder extends Seeder | ||
| { | ||
| public function run(): void | ||
| { | ||
| $this->call(DemoDatabaseSeeder::class); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| <?php | ||
|
|
||
| namespace Modules\Demo\Database\Seeders; | ||
|
|
||
| use App\Enums\Role; | ||
| use App\Models\User; | ||
| use Carbon\Carbon; | ||
| use Illuminate\Database\Seeder; | ||
| use Modules\Billing\Database\Seeders\BillingDatabaseSeeder; | ||
| use Modules\Billing\Models\CheckoutSession; | ||
| use Modules\Billing\Models\Customer; | ||
| use Modules\Billing\Models\Invoice; | ||
| use Modules\Billing\Models\Payment; | ||
| use Modules\Billing\Models\PaymentMethod; | ||
| use Modules\Billing\Models\Price; | ||
| use Modules\Billing\Models\Subscription; | ||
| use Modules\Roadmap\Database\Seeders\RoadmapDatabaseSeeder; | ||
| use Modules\Roadmap\Enums\VoteType; | ||
| use Modules\Roadmap\Models\RoadmapItem; | ||
| use Modules\Roadmap\Models\RoadmapVote; | ||
|
|
||
| class DemoDatabaseSeeder extends Seeder | ||
| { | ||
| public function run(): void | ||
| { | ||
| $this->call([ | ||
| BillingDatabaseSeeder::class, | ||
| RoadmapDatabaseSeeder::class, | ||
| ]); | ||
|
|
||
| $proMonthly = Price::where('provider_price_id', 'price_1SyadREx2sHJcHgwCt0ReZEJ')->firstOrFail(); | ||
| $proYearly = Price::where('provider_price_id', 'price_1SyaCQEx2sHJcHgwEC9VmwSZ')->firstOrFail(); | ||
| $teamMonthly = Price::where('provider_price_id', 'price_1SyaL0Ex2sHJcHgwWaaTGLgo')->firstOrFail(); | ||
| $teamYearly = Price::where('provider_price_id', 'price_1SyaLWEx2sHJcHgw3fQdYV0J')->firstOrFail(); | ||
|
|
||
| $users = User::factory()->count(30)->create(); | ||
| foreach ($users as $user) { | ||
| $user->assignRole(Role::USER->value); | ||
| } | ||
|
|
||
| $customers = collect(); | ||
| $paymentMethods = collect(); | ||
| foreach ($users->take(25) as $user) { | ||
| $customer = Customer::factory()->withAddress()->create(['user_id' => $user->id]); | ||
| $paymentMethod = PaymentMethod::factory()->default()->visa()->create(['customer_id' => $customer->id]); | ||
| $customers->push($customer); | ||
| $paymentMethods->push($paymentMethod); | ||
| } | ||
|
|
||
| // 12 month-start dates, oldest first, for backdating | ||
| $months = collect(range(11, 0))->map(fn ($i) => now()->subMonths($i)->startOfMonth()); | ||
|
|
||
| // [customerIndex, price, state] | ||
| $assignments = [ | ||
| [0, $proMonthly, 'active'], | ||
| [1, $proMonthly, 'active'], | ||
| [2, $proMonthly, 'active'], | ||
| [3, $proMonthly, 'active'], | ||
| [4, $proMonthly, 'active'], | ||
| [5, $proMonthly, 'active'], | ||
| [6, $proMonthly, 'active'], | ||
| [7, $proMonthly, 'active'], | ||
| [8, $proMonthly, 'active'], | ||
| [9, $proMonthly, 'active'], | ||
| [10, $proMonthly, 'active'], | ||
| [11, $proMonthly, 'active'], | ||
| [12, $proYearly, 'active'], | ||
| [13, $proYearly, 'active'], | ||
| [14, $proYearly, 'active'], | ||
| [15, $proYearly, 'active'], | ||
| [16, $proYearly, 'active'], | ||
| [17, $teamMonthly, 'active'], | ||
| [18, $teamMonthly, 'active'], | ||
| [19, $teamMonthly, 'active'], | ||
| [20, $teamMonthly, 'active'], | ||
| [21, $teamYearly, 'active'], | ||
| [22, $teamYearly, 'active'], | ||
| [23, $proMonthly, 'onTrial'], | ||
| [24, $proMonthly, 'onTrial'], | ||
| // Cancelled prior subscriptions reusing the same customers | ||
| [0, $proMonthly, 'cancelled'], | ||
| [1, $teamMonthly, 'cancelled'], | ||
| [2, $proYearly, 'cancelled'], | ||
| // Past due | ||
| [3, $teamMonthly, 'pastDue'], | ||
| [4, $proMonthly, 'pastDue'], | ||
| ]; | ||
|
|
||
| $activeSubscriptions = collect(); | ||
| $monthIndex = 0; | ||
|
|
||
| foreach ($assignments as [$customerIndex, $price, $state]) { | ||
| $customer = $customers->get($customerIndex); | ||
| $paymentMethod = $paymentMethods->get($customerIndex); | ||
| $createdAt = $months[$monthIndex % 12]; | ||
| $monthIndex++; | ||
|
|
||
| $factory = Subscription::factory()->state([ | ||
| 'customer_id' => $customer->id, | ||
| 'price_id' => $price->id, | ||
| 'payment_method_id' => $paymentMethod->id, | ||
| ]); | ||
|
|
||
| $factory = match ($state) { | ||
| 'cancelled' => $factory->cancelled(), | ||
| 'pastDue' => $factory->pastDue(), | ||
| 'onTrial' => $factory->onTrial(), | ||
| default => $factory, | ||
| }; | ||
|
|
||
| $subscription = $factory->create(['created_at' => $createdAt]); | ||
|
|
||
| if (in_array($state, ['active', 'onTrial', 'pastDue'])) { | ||
| $customer->user->assignRole(Role::SUBSCRIBER->value); | ||
| } | ||
|
|
||
| if ($state === 'active') { | ||
| $activeSubscriptions->push($subscription); | ||
| } | ||
| } | ||
|
|
||
| // Payments: one per month per active subscription since its creation. | ||
| // This produces a naturally growing monthly revenue trend. | ||
| $activeSubscriptions = Subscription::whereIn('id', $activeSubscriptions->pluck('id'))->with('price')->get(); | ||
|
|
||
| foreach ($activeSubscriptions as $subscription) { | ||
| $cursor = Carbon::parse($subscription->created_at)->startOfMonth(); | ||
| $nowMonth = now()->startOfMonth(); | ||
|
|
||
| while ($cursor <= $nowMonth) { | ||
| $succeeded = fake()->boolean(90); | ||
|
|
||
| $paymentFactory = Payment::factory()->state([ | ||
| 'customer_id' => $subscription->customer_id, | ||
| 'subscription_id' => $subscription->id, | ||
| 'price_id' => $subscription->price_id, | ||
| 'amount' => $subscription->price->amount, | ||
| ]); | ||
|
|
||
| if (! $succeeded) { | ||
| $paymentFactory = $paymentFactory->failed(); | ||
| } | ||
|
|
||
| $payment = $paymentFactory->create(['created_at' => $cursor->copy()]); | ||
|
|
||
| if ($succeeded) { | ||
| Invoice::factory()->create([ | ||
| 'customer_id' => $subscription->customer_id, | ||
| 'subscription_id' => $subscription->id, | ||
| 'payment_id' => $payment->id, | ||
| 'subtotal' => $subscription->price->amount, | ||
| 'total' => $subscription->price->amount, | ||
| 'paid_at' => $cursor->copy(), | ||
| 'created_at' => $cursor->copy(), | ||
| ]); | ||
| } | ||
|
|
||
| $cursor->addMonth(); | ||
| } | ||
| } | ||
|
|
||
| // Checkout sessions spread across 12 months for the conversion chart. | ||
| // ~2-3 completed, 1 abandoned, 0-1 expired per month → ~67% conversion rate. | ||
| foreach ($months as $month) { | ||
| CheckoutSession::factory() | ||
| ->completed() | ||
| ->count(fake()->numberBetween(2, 3)) | ||
| ->create(['customer_id' => null, 'price_id' => $proMonthly->id, 'created_at' => $month]); | ||
|
|
||
| CheckoutSession::factory() | ||
| ->abandoned() | ||
| ->create(['customer_id' => null, 'price_id' => $proMonthly->id, 'created_at' => $month]); | ||
|
|
||
| if (fake()->boolean(50)) { | ||
| CheckoutSession::factory() | ||
| ->expired() | ||
| ->create(['customer_id' => null, 'price_id' => $proMonthly->id, 'created_at' => $month]); | ||
| } | ||
| } | ||
|
|
||
| // Roadmap votes: each demo user votes on 3-6 random items. | ||
| $roadmapItems = RoadmapItem::all(); | ||
| foreach ($users as $user) { | ||
| $itemsToVote = $roadmapItems->random(fake()->numberBetween(3, 6)); | ||
| foreach ($itemsToVote as $item) { | ||
| RoadmapVote::firstOrCreate( | ||
| ['roadmap_item_id' => $item->id, 'user_id' => $user->id], | ||
| ['type' => fake()->randomElement([VoteType::Up, VoteType::Down])] | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.