๐ Hello Amazing Hive Community!
In our ReactJS adventure so far, weโve been on a wild dev ride โ from fixing rebellious NavBars to brewing delicious Toast notifications ๐, and even sprinkling in some secure login sorcery โจ.
So far, the app could load cashback details right after you log in โ but hey, why stop there?
We decided to also show a monthly cashback claim historyโฆ because history matters (and so does money ๐ต).
๐ Learning Journey Recap
Hereโs the Netflix Series Recap of my React learning saga so far ๐ฌ๐
- ๐ Day 1 โ Fresh React app + AIOHA integration!
- ๐งญ Day 2 โ Routing drama & rebellious NavBar ๐ฅ
- ๐ ๏ธ Day 3 โ Layout & routing rescue mission ๐
- ๐ง Day 4 โ State & effect chaos ๐
- ๐งน Day 5 โ Path spaghetti cleanup ๐
- ๐ก Day 6 โ Context + API magic ๐ช
- ๐ Day 7 โ Toasts that make you smile ๐
- ๐ Day 8 โ Login spells ๐ฎ
- ๐ Day 9 โ Fun tweaks & giggles ๐
- ๐ Day 10 โ Smooth account switching + JWT freshness
- ๐ Day 11 โ Cashback API unlocked ๐
- ๐ต Day 12 โ Cashback ClaimBox: UI glory โจ
๐ก The Big Idea
The cashback API already sends us:
- available cashback ๐ฐ
- AND your monthly claimed history ๐
But we weren't displaying the monthly list yet.
๐ค So the mission was clear:
Show users what theyโve claimed this month โ in style!
๐งช Attempt 1: The (Not-So-Mobile-Friendly) Table
Result?
Horizontal scroll. My biggest enemy. โ
Nope. Deleted instantly ๐
๐ Attempt 2: Cards
Also nope โ
Cards confused users because we already had one for available cashback.
๐ Attempt 3: The Winning List ๐ฏ
This DaisyUI list was love at first sight โค๏ธ.
But before beautyโฆ came the brains ๐ง .
๐ Parsing the JSON Response
API returns:
- memo
- invoice ๐งพ
- timestamp โณ
- cashback amount ๐ธ
๐ช Extracting Business Name
Regex magic to the rescue:
const regexBusinessName = (memo: string) => {
const match = memo.match(
/&(?:\s*adding?\s*review\s*of\s*)(.*?)\s*-\s*http/i
);
if (match) {
const businessName = match[1];
return businessName;
} else {
return "Cafe Coffee Jitters";
}
};
๐ผ Getting Business Image
const getBusinessImage = (username: string) => {
const filteredItems = businesses.filter(
(b) => b.profile?.displayName === 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";
}
};
๐ Business Review Link
const linkToPost = (memo: string) => {
const match = memo.match(/-\s*(https?:\/\/\S+)/i);
if (match) {
const link = match[1];
return link;
} else {
return "https://hive.blog/@shaktimaaan/ylgfiaqv";
}
};
๐งพ Invoice ID Shortcode
const invoice = (memo: string) => {
const match = memo.match(/\(([^)]+)\)/);
if (match) {
const invoiceId = match[1];
return invoiceId;
} else {
return "HDC-XYMYX";
}
};
๐จ Rendering the Monthly Cashback History List
return (
<div>
<ul className="list bg-base-100 rounded-box shadow-md">
<li className="p-4 pb-2 text-xs opacity-60 tracking-wide">
Your claims from this month
</li>
{monthly?.map((claim, index) => (
<li className="list-row" key={index} onClick={()=> window.open(linkToPost(claim.memo), "_blank")}>
<div className="text-4xl font-thin opacity-30 tabular-nums">
{index + 1}
</div>
<div>
<img
className="size-10 rounded-box"
src={getBusinessImage(regexBusinessName(claim.memo))}
/>
</div>
<div>
<div>{regexBusinessName(claim.memo)}</div>
<div className="text-xs uppercase font-semibold opacity-60">{invoice(claim.memo)}</div>
</div>
<div>
<div>{claim.amount}</div>
<div>{dayjs(claim.timestamp).fromNow()}</div>
</div>
</li>
))}
</ul>
</div>
);
๐ How Does it Look?
Cash back claim history from this month
๐ Wanna See the Damn Code?
- GitHub Repo:
https://github.com/sag333ar/react-distriator
- Direct Commit:
https://github.com/sag333ar/react-distriator/commit/e0703d66f1c1cdec3b1d406b32973512ec5f6005
- Snapshot View:
https://github.com/sag333ar/react-distriator/tree/e0703d66f1c1cdec3b1d406b32973512ec5f6005
๐ Thank You for Surviving My Tech Rant!
- Hope you got a smile, a lesson, and maybe even a bit of cashback happiness ๐
- ๐ฅ More Power to the Hive Community ๐
- ๐ Hive to the moon and beyond! โจ
- ๐ See you in the next post! ๐ฅณ
๐ Final Note
- I asked perplexity to help optimize this post to make it more readable and viewer-friendly.
- Here is the link where you can find both original content & improvements made by AI
- https://www.perplexity.ai/search/beeac6de-9d94-42e8-b12f-c6d8d1375838
๐ My Contributions to โฆ๏ธ Hive Ecosystem
Contribution | To | Hive | Ecosystem |
---|---|---|---|
Hive Witness Node | Hive API Node (in progress) | 3Speak Video Encoder Node Operator (highest number of nodes) | 3Speak Mobile App Developer |
3Speak Podcast App Developer | 3Speak Shorts App Developer | 3Speak Support & Maintenance Team | Distriator Developer |
CheckinWithXYZ | Hive Inbox | HiFind | Hive Donate App |
Contributed to HiveAuth Mobile App | Ecency โ 3Speak Integration | Ecency โ InLeo Integration | Ecency โ Actifit Integration |
Hive Stats App | Vote for Witness App | HiveFlutterKit | New 3Speak App |
๐ Support Back
โค๏ธ Appreciate my work? Consider supporting @threespeak & @sagarkothari88! โค๏ธ
Vote | For | Witness |
---|---|---|
sagarkothari88 | @sagarkothari88 | |
threespeak | @threespeak |