Skip to content

Commit

Permalink
feat: adjust balance coin format (#16)
Browse files Browse the repository at this point in the history
* feat: adjust balance coin format

* feat: adjust balance coin format

* feat: add command to optimize app
  • Loading branch information
mhdramadhanarvin authored Sep 20, 2024
1 parent 8cceb22 commit 05c9c19
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ jobs:
cd /home/${{ secrets.SSH_USERNAME }}/stepcash
unzip -o app.zip -d /home/${{ secrets.SSH_USERNAME }}/stepcash/
rm -rf app.zip
/opt/alt/php83/usr/bin/php artisan optimize
/opt/alt/php83/usr/bin/php artisan filament:optimize
49 changes: 26 additions & 23 deletions app/Filament/Resources/RewardResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static function table(Table $table): Table

return ' Coin ~= Rp. ' . $state * ($coinRate->rupiah / $coinRate->coin);
}),
TextColumn::make('status')->badge(),
TextColumn::make('status')->badge()->sortable(),
ImageColumn::make('thumbnail'),
])
->filters([
Expand All @@ -125,28 +125,31 @@ public static function table(Table $table): Table
->disabled($isLocked)
->before(function (Model $record, array $data) {
// Runs after the form fields are saved to the database.
if ($record->status == RewardEnum::WaitingApproving && $data['status'] == 'publish') {
Notification::make()
->success()
->title('Penambahan Produk Disetujui')
->body('Produk yang kamu tambahan sudah disetujui admin, sekarang produk kamu sudah tampil di halaman hadiah pengguna')
->actions([
Action::make('lihat')
->button()
->url(RewardResource::getUrl('index')),
])
->sendToDatabase($record->partner->user);
} elseif ($record->status == RewardEnum::WaitingApproving && $data['status'] == 'draft') {
Notification::make()
->danger()
->title('Penambahan Produk Ditolak')
->body('Produk yang kamu tambahkan ditolak, silahkan tambahkan produk lain')
->actions([
Action::make('lihat')
->button()
->url(RewardResource::getUrl('index')),
])
->sendToDatabase($record->partner->user);
$user = User::find(Auth::id());
if ($user->hasRole('super_admin')) {
if ($record->status == RewardEnum::WaitingApproving && $data['status'] == 'publish') {
Notification::make()
->success()
->title('Penambahan Produk Disetujui')
->body('Produk yang kamu tambahan sudah disetujui admin, sekarang produk kamu sudah tampil di halaman hadiah pengguna')
->actions([
Action::make('lihat')
->button()
->url(RewardResource::getUrl('index')),
])
->sendToDatabase($record->partner->user);
} elseif ($record->status == RewardEnum::WaitingApproving && $data['status'] == 'draft') {
Notification::make()
->danger()
->title('Penambahan Produk Ditolak')
->body('Produk yang kamu tambahkan ditolak, silahkan tambahkan produk lain')
->actions([
Action::make('lihat')
->button()
->url(RewardResource::getUrl('index')),
])
->sendToDatabase($record->partner->user);
}
}
})
/*Tables\Actions\DeleteAction::make()*/
Expand Down
3 changes: 2 additions & 1 deletion resources/js/Components/Modals/ModalDetailHistoryClaim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Badge } from "../Badge";
import CoinIcon from "../CoinIcon";
import SecondaryButton from "../SecondaryButton";
import {
formatedBalance,
limitCharacter,
RewardClaimIntruction,
RewardClaimStatusLabel,
Expand Down Expand Up @@ -100,7 +101,7 @@ export const ModalDetailHistoryClaim = ({
</div>
<div className="col-span-8 text-lg inline-flex px-3">
<CoinIcon />
{data?.price}
{formatedBalance(data?.price ?? 0)}
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Layouts/AuthenticatedLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import {
import NavIcon from "@/Components/NavIcon";
import CoinIcon from "@/Components/CoinIcon";
import { useApi } from "@/utils/useApi";
import { formatedBalance } from "@/utils/manipulation";

export default function Authenticated({
user,
header,
children,
}: PropsWithChildren<{ user: User; header?: ReactNode }>) {
const [showingNavigationDropdown, setShowingNavigationDropdown] =
useState(false);
const [showingNavigationDropdown] = useState(false);

const { data } = useApi({
key: "profile",
Expand Down Expand Up @@ -109,7 +109,7 @@ export default function Authenticated({
<button className="inline-flex items-center justify-center p-2 rounded-md text-gray-700 text-3xl hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 focus:text-gray-500 transition duration-150 ease-in-out">
<CoinIcon />
<span className="text-xl font-semibold">
{profile.coin}
{formatedBalance(profile?.coin ?? 0)}
</span>
</button>
</div>
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default function Dashboard({ auth }: PageProps) {
/>
</div>
<div className="py-2">
<span>{step.time_spent} min</span>
<span>{step.time_spent ?? 0} min</span>
</div>
</div>
<div className="totalDistance">
Expand All @@ -226,7 +226,7 @@ export default function Dashboard({ auth }: PageProps) {
/>
</div>
<div className="py-2">
<span>{step.distance} KM</span>
<span>{step.distance ?? 0} KM</span>
</div>
</div>
<div className="totalCalory">
Expand All @@ -237,7 +237,7 @@ export default function Dashboard({ auth }: PageProps) {
/>
</div>
<div className="py-2">
<span>{step.calory} Cal</span>
<span>{step.calory ?? 0} Cal</span>
</div>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions resources/js/Pages/Rewards/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Modal from "@/Components/Modal";
import SecondaryButton from "@/Components/SecondaryButton";
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { PageProps, ResponseGlobal, Rewards } from "@/types";
import { formatedBalance } from "@/utils/manipulation";
import { useApi } from "@/utils/useApi";
import {
faChevronLeft,
Expand Down Expand Up @@ -116,7 +117,7 @@ export default function Detail({ auth, id }: PageProps<{ id: number }>) {
<div className="max-w-lg rounded-2xl hover:shadow-xl hover:shadow-indigo-50 flex flex-col mb-64">
<img
src={reward?.thumbnail}
className="shadow rounded-lg overflow-hidden border object-cover h-48"
className="shadow rounded-lg overflow-hidden border object-contain object-center h-48"
/>
<div className="mt-8 px-1">
<div className="grid grid-cols-4">
Expand All @@ -132,7 +133,7 @@ export default function Detail({ auth, id }: PageProps<{ id: number }>) {
<div className="inline-flex">
<CoinIcon />
<span className="text-xl font-semibold">
{reward?.price}
{formatedBalance(reward?.price ?? 0)}
</span>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion resources/js/Pages/Rewards/History.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ModalDetailHistoryClaim } from "@/Components/Modals/ModalDetailHistoryC
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { PageProps, RewardClaims } from "@/types";
import {
formatedBalance,
RewardClaimStatusLabel,
RewardClaimStatusLabelColor,
} from "@/utils/manipulation";
Expand Down Expand Up @@ -132,7 +133,7 @@ export default function History({
borderColor: "divider",
}}
>
{data.price} Coin
{formatedBalance(data.price)} Coin
</CardOverflow>
</Card>
))}
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Pages/Rewards/List.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AuthenticatedLayout from "@/Layouts/AuthenticatedLayout";
import { PageProps, Rewards } from "@/types";
import { limitCharacter } from "@/utils/manipulation";
import { formatedBalance, limitCharacter } from "@/utils/manipulation";
import { useApi } from "@/utils/useApi";
import { faClockRotateLeft } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
Expand Down Expand Up @@ -87,15 +87,15 @@ export default function List({ auth }: PageProps) {
px: 1,
writingMode: "vertical-rl",
justifyContent: "center",
fontSize: "xs",
fontSize: 10,
fontWeight: "xl",
letterSpacing: "1px",
textTransform: "uppercase",
borderLeft: "1px solid",
borderColor: "divider",
}}
>
{data.price} Coin
{formatedBalance(data.price)} Coin
</CardOverflow>
</Card>
</Link>
Expand Down
7 changes: 7 additions & 0 deletions resources/js/utils/manipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,10 @@ export const RewardClaimIntruction = ({
return "";
}
};

export const formatedBalance = (balance: number): string => {
if (balance >= 1000) {
return balance / 1000 + "K";
}
return balance.toString();
};
2 changes: 1 addition & 1 deletion routes/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
use Illuminate\Support\Facades\Schedule;

Schedule::command('queue:work')->everyTwoSeconds();
Schedule::command('app:convert-steps-to-coin')->dailyAt('23:00');
Schedule::command('app:convert-steps-to-coin --stop-when-empty')->dailyAt('23:00');

0 comments on commit 05c9c19

Please sign in to comment.