-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0aec7c1
commit b87c4dc
Showing
15 changed files
with
278 additions
and
20 deletions.
There are no files selected for viewing
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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,29 @@ | ||
import { ICoupon } from '../react-app-env'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
export const currentCoupons: ICoupon[] = [ | ||
{ | ||
id: '1', | ||
name: 'Save 50%', | ||
discount: 0.5, | ||
code: uuidv4(), | ||
stateUsing: 'unused', | ||
imgUrl: 'images/coupons/50.png', | ||
}, | ||
{ | ||
id: '2', | ||
name: 'Save 40%', | ||
discount: 0.4, | ||
code: uuidv4(), | ||
stateUsing: 'unused', | ||
imgUrl: 'images/coupons/40.png', | ||
}, | ||
{ | ||
id: '3', | ||
name: 'Save 30%', | ||
discount: 0.3, | ||
code: uuidv4(), | ||
stateUsing: 'unused', | ||
imgUrl: 'images/coupons/30.png', | ||
} | ||
] |
This file contains 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,62 @@ | ||
import React, { useState } from 'react'; | ||
import { setError } from '../../store/actions'; | ||
|
||
type Props = { | ||
id: string, | ||
name: string, | ||
discount: number, | ||
code: string, | ||
stateUsing: string, | ||
imgUrl: string, | ||
}; | ||
|
||
export const CardCoupon: React.FC<Props> = ({ | ||
id, | ||
name, | ||
discount, | ||
code, | ||
stateUsing, | ||
imgUrl, | ||
}) => { | ||
|
||
const [isCopied, setIsCopied] = useState(false); | ||
|
||
const handleCopyClick = () => { | ||
navigator.clipboard.writeText(`${code}`) | ||
.then(() => { | ||
setIsCopied(true); | ||
}) | ||
.catch((error) => { | ||
setError(`Error copying to clipboard: ${error}`); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="m-2 rounded-3xl ring-1 ring-gray-200"> | ||
<div className="p-2 flex flex-wrap justify-center gap-2"> | ||
|
||
<div className="flex mb-2 lg:w-[400px] lg:h-[260px]"> | ||
<img className="rounded-3xl" src={imgUrl} alt={name} /> | ||
</div> | ||
|
||
<div className="rounded-2xl bg-gray-50 p-3 text-center ring-1 ring-inset ring-gray-900/5"> | ||
<div className="mx-auto max-w-xs p-2"> | ||
<p className="text-xl font-semibold text-gray-600 mb-1"><span className="text-base">Name:</span> {name}</p> | ||
<p className="text-xl font-semibold text-gray-600 mb-1"><span className="text-base">ID:</span> {id}</p> | ||
<p className="text-xl font-semibold text-gray-600 mb-1"><span className="text-base">State:</span> {stateUsing}</p> | ||
<p className="text-xl font-semibold text-gray-600 mb-1"><span className="text-base">Save:</span> {`${discount * 100} %`}</p> | ||
<p className="text-xl font-semibold text-gray-600 mb-1"><span className="text-base">Code:</span> {`${code.slice(0, 6)}...`}</p> | ||
</div> | ||
|
||
{ stateUsing === 'unused' && <button | ||
type="button" | ||
onClick={handleCopyClick} | ||
className="block w-full rounded-md bg-indigo-600 px-3.5 py-2.5 text-center text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" | ||
> | ||
{isCopied ? 'Copied!' : 'Copy to Clipboard'} | ||
</button>} | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains 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 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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 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,55 @@ | ||
import React, { useEffect } from 'react' | ||
import logo from '../../images/svg/logo.svg'; | ||
import home from '../../images/svg/home.svg'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { getCoupons, getError } from '../../store/selectors'; | ||
import { Error } from '../../components/Error/Error'; | ||
import { setCoupons } from '../../store/actions'; | ||
import { CardCoupon } from '../../components/CardCoupon/CardCoupon'; | ||
import { currentCoupons } from '../../assets/coupon'; | ||
|
||
export function CouponsPage() { | ||
const dispatch = useDispatch(); | ||
const error = useSelector(getError); | ||
const coupons = useSelector(getCoupons); | ||
|
||
useEffect(() => { | ||
dispatch(setCoupons(currentCoupons)); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{error && <Error />} | ||
<div className="bg-white p-6 m-4 rounded-3xl shadow-lg ring-1 ring-gray-900/5"> | ||
<a href="#" className=" flex m-1.5 p-1.5"> | ||
<span className="sr-only">VAM</span> | ||
<img className="h-8 w-auto mr-3" src={logo} alt="logo" /> | ||
<img className="h-8 w-auto" src={home} alt="home" title="Back to home" /> | ||
</a> | ||
</div> | ||
|
||
<div className="flex flex-wrap justify-center p-6 m-4 rounded-3xl bg-white shadow-lg ring-1 ring-gray-900/5"> | ||
|
||
{coupons.length === 0 | ||
? <p className="p-6"> No coupons!</p> | ||
: coupons.map((item) => { | ||
return ( | ||
<div key={item.id} className="p-6 m-4 rounded-3xl bg-white shadow-lg ring-1 ring-gray-900/5"> | ||
<div className="text-xl w-8 h-8 bg-black rounded-full font-bold text-white text-center align mb-2">{item.id}</div> | ||
<CardCoupon | ||
key={item.id} | ||
id={item.id} | ||
name={item.name} | ||
discount={item.discount} | ||
code={item.code} | ||
stateUsing={item.stateUsing} | ||
imgUrl={item.imgUrl} | ||
/> | ||
</div> | ||
) | ||
})} | ||
|
||
</div > | ||
</> | ||
) | ||
} |
Oops, something went wrong.