Skip to content

Added expiration date to the website #1587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/main_endpoints/routes/Cleezy.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
} else if (!await decodeToken(req)) {
return res.sendStatus(UNAUTHORIZED);
}
const { url, alias } = req.body;
let jsonbody = { url, alias: alias || null };
const { url, alias, expiration_date : expirationDate } = req.body;
let jsonbody = { url, alias: alias || null, expiration_date: expirationDate || null };

Check failure on line 68 in api/main_endpoints/routes/Cleezy.js

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Identifier 'expiration_date' is not in camel case
try {
const response = await axios.post(CLEEZY_URL + '/create_url', jsonbody);
const data = response.data;
Expand Down
4 changes: 2 additions & 2 deletions src/APIFunctions/Cleezy.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
return status;
}

export async function createUrl(url, alias = null, token) {
export async function createUrl(url, alias = null, expirationDate = null, token) {
let status = new ApiResponse();
const urlToAdd = { url, alias };
const urlToAdd = { url, alias, expiration_date : expirationDate };

Check failure on line 37 in src/APIFunctions/Cleezy.js

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Identifier 'expiration_date' is not in camel case
try {
const url = new URL('/api/Cleezy/createUrl', BASE_API_URL);
const response = await axios
Expand Down
58 changes: 57 additions & 1 deletion src/Pages/URLShortener/URLShortener.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default function URLShortenerPage(props) {
const [showUrlInput, setShowUrlInput] = useState(false);
const [useGeneratedAlias, setUseGeneratedAlias] = useState(true);
const [alias, setAlias] = useState('');
const [useExpirationDate, setUseExpirationDate] = useState(true);
const [expirationDate, setExpirationDate] = useState('');
const [allUrls, setAllUrls] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState();
Expand Down Expand Up @@ -61,13 +63,15 @@ export default function URLShortenerPage(props) {
const response = await createUrl(
url.trim(),
alias.trim(),
expirationDate.trim(),
props.user.token
);
if (!response.error) {
setAllUrls([...allUrls, response.responseData]);
setAliasTaken(false);
setUrl('');
setAlias('');
setExpirationDate('');
setShowUrlInput(false);
setTotal(total + 1);
setSuccessMessage(`Sucessfully created shortened link ${response.responseData.link}`);
Expand Down Expand Up @@ -149,6 +153,12 @@ export default function URLShortenerPage(props) {
}
}, [useGeneratedAlias]);

useEffect(() => {
if(useExpirationDate) {
setExpirationDate('');
}
}, [useExpirationDate]);

useEffect(() => {
if (!showUrlInput) {
setAlias('');
Expand Down Expand Up @@ -271,6 +281,16 @@ export default function URLShortenerPage(props) {
</label>
</div>
</div>

<div className="col-span-3">
<div className="form-control">
<label className="label cursor-pointer">
<span className="label-text">Use Expiration Date</span>
<input type="checkbox" className="toggle" checked={useExpirationDate} onChange={(e) => setUseExpirationDate(e.target.checked)} />
</label>
</div>
</div>

{!useGeneratedAlias && (

<div className="sm:col-span-4">
Expand All @@ -288,6 +308,25 @@ export default function URLShortenerPage(props) {
</div>
</div>
)}

{!useExpirationDate && (

<div className="sm:col-span-4">
<label htmlFor="email" className={LABEL_CLASS}>
Expiration Date
</label>
<div className="mt-2">
<input
id="expirationDate"
name="expirationDate"
value={expirationDate}
onChange={e => setExpirationDate(e.target.value + ':00')}
type="datetime-local"
className={INPUT_CLASS}
/>
</div>
</div>
)}
</div>
</div>
</div>
Expand Down Expand Up @@ -425,6 +464,7 @@ export default function URLShortenerPage(props) {
{[
{ title: 'URL', className: 'text-base text-white/70', columnName: 'alias' },
{ title: 'Created At', className: 'text-base text-white/70 hidden text-center sm:table-cell', columnName: 'created_at' },
{ title: 'Expires At', className: 'text-base text-white/70 text-center', columnName: 'expires_at' },
{ title: 'Times Used', className: 'text-base text-white/70 text-center', columnName: 'used' },
{ title: 'Delete', className: 'text-base text-white/70 text-center' }
].map(({ title, className, columnName = null }) => (
Expand Down Expand Up @@ -458,7 +498,23 @@ export default function URLShortenerPage(props) {
</td>
<td className='hidden md:table-cell'>
<div className='flex items-center justify-center'>
{new Date(url.created_at).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })} </div>
{new Date(url.created_at).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })}
</div>
</td>
<td className='hidden md:table-cell'>
<div className='flex items-center justify-center'>
{(() => {
if (url.expires_at === null) {
return (
<div>No Expiration Date</div>
);
} else {
return (
<div>{new Date(url.expires_at).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit' })}</div>
);
}
})()}
</div>
</td>
<td className='hidden md:table-cell'>
<div className='flex items-center justify-center'>
Expand Down
Loading