๐ŸŽฏ ReactJS Adventures: Designing a Cashback ClaimBox for Distriator ๐Ÿ’ต ๐Ÿš€

in HiveDevs โ€ข 10 days ago

Hello Hive Community Members ๐Ÿ‘‹,

The Distriator app is getting a ReactJS glow-up โœจ โ€” and if things go right, we might finally say goodbye to that bloated Flutter build ๐Ÿชฆ.
As always, everything is open source (because sharing is caring โค๏ธ), so if you missed the earlier drama, hereโ€™s your binge-worthy recap ๐Ÿ“บ๐Ÿ‘‡.


๐Ÿ“œ Epic Learning Journey Recap

Missed a day? Hereโ€™s the trail of my glorious ReactJS misadventures:


๐Ÿ’ต Day 12: Designing the Cashback ClaimBox

This time, weโ€™re showing users a beautiful, irresistible โ€œClaim Cashbackโ€ card ๐Ÿ’Œ whenever their cashback is ready to be grabbed.

๐Ÿ’ญ Thought Process

Originally: โ€œLetโ€™s just put a box in the center with a button.โ€
Brain: โŒ โ€œNope, donโ€™t reinvent the wheel.โ€
Solution: Scroll through DaisyUI like itโ€™s Pinterest, and pick something gorgeous.


๐Ÿƒ The Card That Stole My Heart

After scrolling... BAM ๐Ÿ’˜ โ€” this card component caught my eye.

Beautiful card view

JSX? Barely 10 lines ๐Ÿคฏ. Copy. Paste. Letโ€™s roll.

JSX Code snippet for card view


๐Ÿ“ฆ ClaimBox Component

  • Created ClaimBox.tsx
  • Grabbed API attributes:
    • Transaction timestamp ๐Ÿ•’
    • Business name ๐Ÿช
    • Claimable cashback amount ๐Ÿ’ต
    • Transaction amount ๐Ÿ’ณ

API response data


โณ Timer Logic

Cashback = claimable for 2 hours after transaction.
We:

  1. Grab timestamp
  2. Add 2 hrs
  3. Show countdown (HH:MM:SS)
  4. Update every 1 sec โฑ๏ธ
function formatSecondsToHHMMSS(totalSeconds: number): string {
  if (totalSeconds < 0) return '';
  const hours = Math.floor(totalSeconds / 3600);
  const minutes = Math.floor((totalSeconds % 3600) / 60);
  const seconds = parseInt((totalSeconds % 60).toFixed(0));
  const pad = (num: number) => String(num).padStart(2, "0");
  return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`;
}

๐Ÿช Getting Business Info

Using the Business Provider to get:

  • Profile Image ๐Ÿ“ท
  • Display Name ๐Ÿท๏ธ

In this post, we discussed about implementing business provider. From that provider, we'll access businesses. From list of businesses, we'll get business display name & business profile image.

Step 1. Import business provider

import { useBusinesses } from "@/context/BusinessesContext";

Step 2. Declare business provider variable

const { businesses } = useBusinesses();

Step 3. Get Business Profile Display Image

  const getBusinessImage = (username: string) => {
    const filteredItems = businesses.filter(
      (b) => b.distriator?.owner === username
    );
    if (filteredItems.length > 0) {
      return (
        filteredItems[0].profile?.displayImage ||
        "https://img.daisyui.com/images/stock/photo-1606107557195-0e29a4b5b4aa.webp"
      );
    } else {
      return "https://img.daisyui.com/images/stock/photo-1606107557195-0e29a4b5b4aa.webp";
    }
  };

Step 4. Get Business Profile Display Name

  const getBusinessName = (username: string) => {
    const filteredItems = businesses.filter(
      (b) => b.distriator?.owner === username
    );
    if (filteredItems.length > 0) {
      return filteredItems[0].profile?.displayName || "Business Name";
    } else {
      return "Business Name";
    }
  };

๐ŸŽจ Final ClaimBox UI

  return (
    <div className="card bg-base-100 w-96 shadow-sm">
      <figure>
        <img 
          src={getBusinessImage(claim.business)} 
          alt={`${getBusinessName(claim.business)}`} />
      </figure>
      <div className="card-body">
        <h2 className="card-title">{claim.claimValue} Cashback</h2>
        <p>
          Your recent spent of {claim.amount}, at {getBusinessName(claim.business)}, is eligible for claiming a cashback
        </p>
        <div className="card-actions justify-end items-center">
          <span className="text-lg font-bold text-red-600 animate-blink">
            Time Left {timeText}
          </span>
          <button className="btn btn-primary">Claim Now!</button>
        </div>
      </div>
    </div>
  );

๐Ÿ“ Centering the Magic

Show loader if loading, โ€œNo claim availableโ€ if empty, else ClaimBox ๐Ÿ’Ž.

Loader - no claim - cashback

๐Ÿฅ Drumroll... Tada!

npm run dev โ†’ Profit.

Wow wonderful

Looks wonderful, right? ๐Ÿ˜

๐Ÿ›  Open Source Goodness

๐Ÿค” Why Flutter? Why Me?

After this, I questioned my life choicesโ€ฆ Flutter? Native apps? When ReactJS makes it this simple? ๐Ÿ™ƒ
But hey, lesson learned โ€” and we now have ClaimBox integrated ๐ŸŽฏ.

๐Ÿ Power to Hive

  • ๐Ÿš€ Hive to the moon (and beyond!)
  • โค๏ธ Power to Hive community
  • ๐Ÿ’ช Power to Hive blockchain

Thanks for reading! Drop your feedback & see you in the next one โœŒ๏ธ.


๐Ÿ“ Final Note


๐Ÿš€ My Contributions to โ™ฆ๏ธ Hive Ecosystem

ContributionToHiveEcosystem
Hive Witness NodeHive API Node (in progress)3Speak Video Encoder Node Operator (highest number of nodes)3Speak Mobile App Developer
3Speak Podcast App Developer3Speak Shorts App Developer3Speak Support & Maintenance TeamDistriator Developer
CheckinWithXYZHive InboxHiFindHive Donate App
Contributed to HiveAuth Mobile AppEcency โ†” 3Speak IntegrationEcency โ†” InLeo IntegrationEcency โ†” Actifit Integration
Hive Stats AppVote for Witness AppHiveFlutterKitNew 3Speak App

๐Ÿ™Œ Support Back

โค๏ธ Appreciate my work? Consider supporting @threespeak & @sagarkothari88! โค๏ธ


Sort: ย 

This post has been manually curated by @steemflow from Indiaunited community. Join us on our Discord Server.

Do you know that you can earn a passive income by delegating to @indiaunited. We share more than 100 % of the curation rewards with the delegators in the form of IUC tokens. HP delegators and IUC token holders also get upto 20% additional vote weight.

Here are some handy links for delegations: 100HP, 250HP, 500HP, 1000HP.

image.png

100% of the rewards from this comment goes to the curator for their manual curation efforts. Please encourage the curator @steemflow by upvoting this comment and support the community by voting the posts made by @indiaunited..

This post received an extra 7.51% vote for delegating HP / holding IUC tokens.