wip: make screen responsive for mobile and browser.

This commit is contained in:
2025-10-07 12:46:04 +05:30
parent 649fc5acea
commit 72b0fa4378
12 changed files with 1060 additions and 587 deletions

View File

@@ -7,6 +7,7 @@ import { useRouter } from "next/navigation";
import { Providers } from "../../providers";
import { notifications } from '@mantine/notifications';
import dayjs from 'dayjs';
import { useMediaQuery } from '@mantine/hooks';
interface accountData {
stAccountNo: string;
@@ -19,6 +20,7 @@ interface accountData {
export default function Home() {
const [authorized, SetAuthorized] = useState<boolean | null>(null);
const router = useRouter();
const isMobile = useMediaQuery("(max-width: 768px)");
const [accountData, SetAccountData] = useState<accountData[]>([]);
const depositAccounts = accountData.filter(acc => acc.stAccountType !== "LN");
const [selectedDA, setSelectedDA] = useState(depositAccounts[0]?.stAccountNo || "");
@@ -27,7 +29,7 @@ export default function Home() {
const [selectedLN, setSelectedLN] = useState(loanAccounts[0]?.stAccountNo || "");
const selectedLNData = loanAccounts.find(acc => acc.stAccountNo === selectedLN);
const [showBalance, setShowBalance] = useState(false);
const PassExpiryRemains =(dayjs(localStorage.getItem("pswExpiryDate"))).diff(dayjs(),"day")
const PassExpiryRemains = (dayjs(localStorage.getItem("pswExpiryDate"))).diff(dayjs(), "day")
// If back and forward button is clicked
useEffect(() => {
@@ -42,11 +44,11 @@ export default function Home() {
router.push("/login");
};
const handleBeforeUnload = () => {
// logout on tab close / refresh
localStorage.removeItem("access_token");
sessionStorage.removeItem("access_token");
localStorage.clear();
sessionStorage.clear();
// logout on tab close / refresh
localStorage.removeItem("access_token");
sessionStorage.removeItem("access_token");
localStorage.clear();
sessionStorage.clear();
};
window.addEventListener("popstate", handlePopState);
window.addEventListener("beforeunload", handleBeforeUnload);
@@ -112,29 +114,62 @@ export default function Home() {
if (authorized) {
return (
<Providers>
<div>
<Title order={4} style={{ padding: "10px" }}>Accounts Overview</Title>
<Group style={{ flex: 1, padding: "10px 10px 4px 10px", marginLeft: '10px', display: "flex", alignItems: "center", justifyContent: "left", height: "1vh" }}>
<IconEye size={20} />
<Text fw={700} style={{ fontFamily: "inter", fontSize: '17px' }}>Show Balance </Text>
<Switch size="md" onLabel="ON" offLabel="OFF" checked={showBalance}
onChange={(event) => setShowBalance(event.currentTarget.checked)} />
<Box p={isMobile ? "8px" : "10px"}>
<Title order={4} style={{fontSize: isMobile ? "18px" : "22px" }}>
Accounts Overview
</Title>
{/* Show Balance Switch */}
<Group
style={{
flex: 1,
// padding: isMobile ? "5px" : "10px 10px 4px 10px",
marginLeft: isMobile ? 0 : "10px",
display: "flex",
alignItems: "center",
justifyContent: "flex-start",
height: "auto",
gap: isMobile ? 5 : 10,
}}
>
<IconEye size={isMobile ? 16 : 20} />
<Text fw={700} style={{ fontFamily: "inter", fontSize: isMobile ? "14px" : "17px" }}>
Show Balance
</Text>
<Switch
size={isMobile ? "sm" : "md"}
onLabel="ON"
offLabel="OFF"
checked={showBalance}
onChange={(event) => setShowBalance(event.currentTarget.checked)}
/>
</Group>
<div style={{ display: "flex", alignItems: "center", justifyContent: "flex-start", marginLeft: '15px' }}>
<Group grow gap="xl">
{/* Cards Section */}
{isMobile ? (
<Stack gap="md" style={{ width: "100%", marginTop: "10px" }}>
{/* Deposit Account Card */}
<Paper p="md" radius="md" style={{
backgroundColor: '#c1e0f0', width: 350, height: 195, display: 'flex',
flexDirection: 'column', justifyContent: 'space-between'
}}>
<Group gap='xs'>
<IconBuildingBank size={25} />
<Text fw={700}>Deposit Account</Text>
<Paper
p="md"
radius="md"
style={{
backgroundColor: "#c1e0f0",
width: "100%",
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
}}
>
<Group gap="xs">
<IconBuildingBank size={20} />
<Text fw={700} style={{ fontSize: "14px" }}>
Deposit Account
</Text>
{depositAccounts.length > 0 ? (
<Select
data={depositAccounts.map(acc => ({
data={depositAccounts.map((acc) => ({
value: acc.stAccountNo,
label: `${acc.stAccountType}- ${acc.stAccountNo}`
label: `${acc.stAccountType}- ${acc.stAccountNo}`,
}))}
value={selectedDA}
// @ts-ignore
@@ -145,12 +180,172 @@ export default function Home() {
backgroundColor: "white",
color: "black",
marginLeft: 5,
width: 140
}
width: "120px",
},
}}
/>
) : (
<Text c="dimmed" size="sm" ml="sm">No deposit account available</Text>
<Text c="dimmed" size="sm" ml="sm">
No deposit account available
</Text>
)}
</Group>
{depositAccounts.length > 0 ? (
<>
<Text c="dimmed" style={{ fontSize: "12px" }}>
{Number(selectedDAData?.stAccountNo || 0)}
</Text>
<Title order={4} mt="md">
{showBalance
? `${Number(selectedDAData?.stAvailableBalance || 0).toLocaleString("en-IN")}`
: "****"}
</Title>
<Button fullWidth mt="xs" onClick={() => handleGetAccountStatement(selectedDA)}>
Get Statement
</Button>
</>
) : (
<>
<Text c="dimmed" mt="md">
Apply for a deposit account to get started
</Text>
<Button fullWidth mt="xs">
Apply Now
</Button>
</>
)}
</Paper>
{/* Loan Account Card */}
<Paper
p="md"
radius="md"
style={{
backgroundColor: "#c1e0f0",
width: "100%",
display: "flex",
flexDirection: "column",
justifyContent: "space-between",
}}
>
<Group gap="xs">
<IconBuildingBank size={20} />
<Text fw={700} style={{ fontSize: "14px" }}>
Loan Account
</Text>
{loanAccounts.length > 0 ? (
<Select
data={loanAccounts.map((acc) => ({
value: acc.stAccountNo,
label: `${acc.stAccountType}- ${acc.stAccountNo}`,
}))}
value={selectedLN}
// @ts-ignore
onChange={setSelectedLN}
size="xs"
styles={{
input: {
backgroundColor: "white",
color: "black",
marginLeft: 5,
width: "120px",
},
}}
/>
) : (
<Text c="dimmed" size="sm" ml="sm">
No loan account available
</Text>
)}
</Group>
{loanAccounts.length > 0 ? (
<>
<Text c="dimmed" style={{ fontSize: "12px" }}>
{Number(selectedLNData?.stAccountNo || 0)}
</Text>
<Title order={4} mt="md">
{showBalance
? `${Number(selectedLNData?.stAvailableBalance || 0).toLocaleString("en-IN")}`
: "****"}
</Title>
<Button fullWidth mt="xs" onClick={() => handleGetAccountStatement(selectedLN)}>
Get Statement
</Button>
</>
) : (
<>
<Text c="dimmed" mt="md">
Apply for a loan account to get started
</Text>
<Button fullWidth mt="xs">
Apply Now
</Button>
</>
)}
</Paper>
{/* Important Links Card */}
<Paper
p="md"
radius="md"
style={{
width: "100%",
backgroundColor: "#FFFFFF",
border: "1px solid grey",
}}
>
<Title order={5} mb="sm">
Quick Links
</Title>
<Stack gap="xs">
<Button variant="light" color="blue" fullWidth>
Loan EMI Calculator
</Button>
<Button variant="light" color="blue" fullWidth>
Branch Locator
</Button>
<Button variant="light" color="blue" fullWidth>
Customer Care
</Button>
<Button variant="light" color="blue" fullWidth>
FAQs
</Button>
</Stack>
</Paper>
</Stack>
) : (
<Group grow gap="md" style={{ width: "100%", marginTop: "10px" }}>
{/* Desktop Cards */}
{/* Deposit Account Card */}
<Paper p="md" radius="md" style={{ backgroundColor: "#c1e0f0", width: 350, height: 195, display: "flex", flexDirection: "column", justifyContent: "space-between" }}>
<Group gap="xs">
<IconBuildingBank size={25} />
<Text fw={700}>Deposit Account</Text>
{depositAccounts.length > 0 ? (
<Select
data={depositAccounts.map((acc) => ({
value: acc.stAccountNo,
label: `${acc.stAccountType}- ${acc.stAccountNo}`,
}))}
value={selectedDA}
// @ts-ignore
onChange={setSelectedDA}
size="xs"
styles={{
input: {
backgroundColor: "white",
color: "black",
marginLeft: 5,
width: 140,
},
}}
/>
) : (
<Text c="dimmed" size="sm" ml="sm">
No deposit account available
</Text>
)}
</Group>
@@ -158,32 +353,34 @@ export default function Home() {
<>
<Text c="dimmed">{Number(selectedDAData?.stAccountNo || 0)}</Text>
<Title order={2} mt="md">
{showBalance ? `${Number(selectedDAData?.stAvailableBalance || 0).toLocaleString('en-IN')}` : "****"}
{showBalance ? `${Number(selectedDAData?.stAvailableBalance || 0).toLocaleString("en-IN")}` : "****"}
</Title>
<Button fullWidth mt="xs" onClick={() => handleGetAccountStatement(selectedDA)}>Get Statement</Button>
<Button fullWidth mt="xs" onClick={() => handleGetAccountStatement(selectedDA)}>
Get Statement
</Button>
</>
) : (
<>
<Text c="dimmed" mt="md">Apply for a deposit account to get started</Text>
<Button fullWidth mt="xs">Apply Now</Button>
<Text c="dimmed" mt="md">
Apply for a deposit account to get started
</Text>
<Button fullWidth mt="xs">
Apply Now
</Button>
</>
)}
</Paper>
{/* Loan Account Card */}
<Paper p="md" radius="md" style={{
backgroundColor: '#c1e0f0', width: 355, height: 195, display: 'flex',
flexDirection: 'column', justifyContent: 'space-between'
}}
>
<Group gap='xs'>
<Paper p="md" radius="md" style={{ backgroundColor: "#c1e0f0", width: 355, height: 195, display: "flex", flexDirection: "column", justifyContent: "space-between" }}>
<Group gap="xs">
<IconBuildingBank size={25} />
<Text fw={700}>Loan Account</Text>
{loanAccounts.length > 0 ? (
<Select
data={loanAccounts.map(acc => ({
data={loanAccounts.map((acc) => ({
value: acc.stAccountNo,
label: `${acc.stAccountType}- ${acc.stAccountNo}`
label: `${acc.stAccountType}- ${acc.stAccountNo}`,
}))}
value={selectedLN}
// @ts-ignore
@@ -194,12 +391,14 @@ export default function Home() {
backgroundColor: "white",
color: "black",
marginLeft: 30,
width: 140
}
width: 140,
},
}}
/>
) : (
<Text c="dimmed" size="sm" ml="sm">No loan account available</Text>
<Text c="dimmed" size="sm" ml="sm">
No loan account available
</Text>
)}
</Group>
@@ -207,42 +406,60 @@ export default function Home() {
<>
<Text c="dimmed">{Number(selectedLNData?.stAccountNo || 0)}</Text>
<Title order={2} mt="md">
{showBalance ? `${Number(selectedLNData?.stAvailableBalance || 0).toLocaleString('en-IN')}` : "****"}
{showBalance ? `${Number(selectedLNData?.stAvailableBalance || 0).toLocaleString("en-IN")}` : "****"}
</Title>
<Button fullWidth mt="xs" onClick={() => handleGetAccountStatement(selectedLN)}>Get Statement</Button>
<Button fullWidth mt="xs" onClick={() => handleGetAccountStatement(selectedLN)}>
Get Statement
</Button>
</>
) : (
<>
<Text c="dimmed" mt="md">Apply for a loan account to get started</Text>
<Button fullWidth mt="xs">Apply Now</Button>
<Text c="dimmed" mt="md">
Apply for a loan account to get started
</Text>
<Button fullWidth mt="xs">
Apply Now
</Button>
</>
)}
</Paper>
{/* Important Links Card */}
<Paper p="md" radius="md" style={{ width: 300, backgroundColor: '#FFFFFF', marginLeft: '130px', border: '1px solid grey' }}>
<Title order={5} mb="sm">Quick Links </Title>
<Paper p="md" radius="md" style={{ width: 300, backgroundColor: "#FFFFFF", border: "1px solid grey" }}>
<Title order={5} mb="sm">
Quick Links
</Title>
<Stack gap="xs">
<Button variant="light" color="blue" fullWidth>Loan EMI Calculator</Button>
<Button variant="light" color="blue" fullWidth>Branch Locator</Button>
<Button variant="light" color="blue" fullWidth>Customer Care</Button>
<Button variant="light" color="blue" fullWidth>FAQs</Button>
<Button variant="light" color="blue" fullWidth>
Loan EMI Calculator
</Button>
<Button variant="light" color="blue" fullWidth>
Branch Locator
</Button>
<Button variant="light" color="blue" fullWidth>
Customer Care
</Button>
<Button variant="light" color="blue" fullWidth>
FAQs
</Button>
</Stack>
</Paper>
</Group>
</div>
<div style={{ padding: "20px", display: "flex", justifyContent: "left" }}>
)}
{/* Notes Section */}
<Box style={{ padding: "5px", display: "flex", justifyContent: "left" }}>
<Stack>
<Text fw={700}> ** Book Balance includes uncleared effect.</Text>
<Text fw={700}> ** Click on the &quot;Show Balance&quot;to display balance for the Deposit and Loan account.</Text>
<Text fw={400} c="red"> ** Your Password will expire in {PassExpiryRemains} days.</Text>
<Text></Text>
<Text fw={700}> ** Click on the &quot;Show Balance&quot; to display balance for the Deposit and Loan account.</Text>
<Text fw={400} c="red">
** Your Password will expire in {PassExpiryRemains} days.
</Text>
</Stack>
</div>
</div>
</Box>
</Box>
</Providers>
);
}
return null;
}