Skip to content

Commit

Permalink
Merge pull request #241 from JR-prog/pre-demo-fixes
Browse files Browse the repository at this point in the history
Various bug fixes
  • Loading branch information
jay-roe authored Apr 26, 2023
2 parents 3656d81 + d382b45 commit f80b50a
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 44 deletions.
7 changes: 4 additions & 3 deletions app/[locale]/account-required/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import Button from '@/components/Buttons/Button';
import Link from 'next/link';
import { useTranslations } from 'next-intl';
import { useLocale, useTranslations } from 'next-intl';

export default function AccountRequired() {
const t = useTranslations('AccountRequired');
const locale = useLocale();

return (
<div>
Expand All @@ -19,10 +20,10 @@ export default function AccountRequired() {
{t('should-login')}
</p>
<div className="flex space-x-1.5">
<Link href="/login">
<Link href={`/${locale}/login`}>
<Button>{t('sign-in')}</Button>
</Link>
<Link href="/register">
<Link href={`/${locale}/register`}>
<Button>{t('register')}</Button>
</Link>
</div>
Expand Down
14 changes: 2 additions & 12 deletions app/[locale]/admin/lockedList/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export default function LockedList() {

async function unlockAccount(uid: string) {
// get account of the person reported and set accountLocked to false
updateDoc(doc(db.users, uid), {
await updateDoc(doc(db.users, uid), {
accountLocked: false,
});
window.location.reload();
setBanned((curr) => curr.filter((bannedUser) => bannedUser.userId !== uid));
}

return (
Expand All @@ -67,16 +67,6 @@ export default function LockedList() {
<div className="flex items-center justify-center">
<p>{user.name}</p>
</div>
<Button
data-testid="unban-account-btn"
onClick={() => {
unlockAccount(user.userId);
}}
>
Unban account
</Button>
</div>
<div>
<Button
data-testid="unban-account-btn"
onClick={() => {
Expand Down
17 changes: 9 additions & 8 deletions app/[locale]/job-feed/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ export default function Feeds() {
useEffect(() => {
setFilteredJobs([]);
jobs
.filter((job) =>
checkIfJobIsInFilter({
fullTime: fullTime,
partTime: partTime,
internship: internship,
job: job,
searchKey: searchKey,
})
.filter(
(job) =>
checkIfJobIsInFilter({
fullTime: fullTime,
partTime: partTime,
internship: internship,
job: job,
searchKey: searchKey,
}) && job.deadline.toMillis() > new Date().getTime()
)
.forEach((job) => {
setFilteredJobs((cur) => [...cur, job]);
Expand Down
1 change: 1 addition & 0 deletions app/[locale]/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function Login() {
try {
setLoading(true);
await login(email, password);
router.push('/' + locale + '/');
} catch (err) {
console.error(err);
alert(t('alert-failed'));
Expand Down
13 changes: 5 additions & 8 deletions app/[locale]/profile/[uid]/links/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default function Links({ params }) {
let links: UserWithId[] = [];
for (
let i = linkedIndex.current;
i < linkedIndex.current + PAGE_SIZE && i < linkedIds.current.length;
i < linkedIndex.current + PAGE_SIZE && i < linkedIds?.current?.length;
i++
) {
const linkedUser = await getDoc(doc(db.users, linkedIds.current[i]));
Expand Down Expand Up @@ -101,8 +101,10 @@ export default function Links({ params }) {
<>
<p data-testid="welcome-msg" className="mb-3 text-left text-2xl">
{myPage
? `Let's see who your links are.`
: `Let's see who ${user.name}'s links are.`}
? t('view-your-links')
: `${t('view-other-links-start')} ${user.name}${t(
'view-other-links-end'
)}`}
</p>
<CardGrid className="gap-y-4">
{links?.map((link, index) => {
Expand Down Expand Up @@ -144,11 +146,6 @@ export default function Links({ params }) {
data-testid="load-more-button-container"
>
{!allLinksFound ? (
// <LoadMoreButton onClick={() =>
// getLinkInfo().then((links) => {
// setLinks((current) => [...current, ...links]);
// })
// }/>
<Button
className="mx-auto"
data-testid="load-more"
Expand Down
4 changes: 3 additions & 1 deletion app/[locale]/profile/[uid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ export default function ViewProfile({ params }) {
href={`/profile/${params.uid}/links`}
linkedUserIds={user?.linkedUserIds}
/>
{!currentAdmin && <LinkButton profileOwnerUID={params.uid} />}
{!currentAdmin && !currentUser.isCompany && (
<LinkButton profileOwnerUID={params.uid} />
)}
</div>

<ProfileContact email={user.email} phone={user.phone} />
Expand Down
3 changes: 2 additions & 1 deletion components/Buttons/LinkButton/LinkButtonNoNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const LinkButtonNoNumber = ({
const { currentUser, authUser } = useAuth(); // User sending out the request
const [linkIds, setLinkIds] = useState(currentUser.linkedUserIds);
return (
posterUID !== authUser.uid && (
posterUID !== authUser.uid &&
!currentUser.isCompany && (
<button
data-testid="link-btn-no-number"
className="z-50 flex max-w-fit items-center gap-1 rounded-md bg-white bg-opacity-0 p-2 transition-all hover:bg-opacity-10 active:bg-opacity-20"
Expand Down
33 changes: 24 additions & 9 deletions components/Buttons/LinkButton/ViewLinkButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,34 @@ export default function ViewLinkButton({
href?: string;
}) {
const t = useTranslations('Button.Link');

if (href) {
return (
<button
data-testid="view-link-button"
className="mb-3 max-w-fit rounded-xl bg-white bg-opacity-[0.12] p-3 font-semibold transition-all hover:bg-opacity-[0.18]"
>
<Link href={href || ''}>
<span className="flex items-center gap-2">
<LinkIcon />
<p>
{linkedUserIds?.length || 0} {t('links')}
</p>
</span>
</Link>
</button>
);
}

return (
<button
data-testid="view-link-button"
className="mb-3 max-w-fit rounded-xl bg-white bg-opacity-[0.12] p-3 font-semibold transition-all hover:bg-opacity-[0.18]"
className="mb-3 flex max-w-fit cursor-default items-center gap-2 rounded-xl bg-white bg-opacity-[0.12] p-3 font-semibold"
>
<Link href={href || ''}>
<span className="flex items-center gap-2">
<LinkIcon />
<p>
{linkedUserIds?.length || 0} {t('links')}
</p>
</span>
</Link>
<LinkIcon />
<p>
{linkedUserIds?.length || 0} {t('links')}
</p>
</button>
);
}
12 changes: 11 additions & 1 deletion contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { deleteDoc, doc, getDoc, setDoc } from 'firebase/firestore';
import md5 from 'md5';
import { useRouter } from 'next/navigation';
import { useLocale } from 'next-intl';
import LoadingScreen from '@/components/Loading/Loading';
import NavBar from '@/components/NavBar/NavBar';

interface AuthContextType {
currentUser: User;
Expand Down Expand Up @@ -254,9 +256,17 @@ export function AuthProvider({ children }) {
[currentUser, currentAdmin, authUser]
);

// Render loading screen instead of page content while authentication loading
return (
<AuthContext.Provider value={value}>
{!loading && children}
{loading ? (
<main className="flex min-h-screen flex-col bg-purple-background">
<NavBar />
<LoadingScreen />
</main>
) : (
children
)}
</AuthContext.Provider>
);
}
3 changes: 3 additions & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@
"loading": "Wird geladen...",
"invalid": "Ungültiger Benutzer.",
"links": {
"view-your-links": "Mal sehen, wer Ihre Links sind.",
"view-other-links-start": "Mal sehen, wer",
"view-other-links-end": "s Links sind.",
"login-first": "Sie sollten sich zuerst anmelden.",
"sign-in": "Anmelden",
"register": "Registrieren",
Expand Down
5 changes: 4 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@
"loading": "Loading...",
"invalid": "Invalid User.",
"links": {
"view-your-links": "Let's see who your links are.",
"view-other-links-start": "Let's see who",
"view-other-links-end": "'s links are.",
"login-first": "You should login first.",
"sign-in": "Sign In",
"register": "Register",
Expand Down Expand Up @@ -450,7 +453,7 @@
"should-login": "You should login first.",
"login": "Login",
"register": "Register",
"confirm-unsaved": "Unsaved changes will be lost. Conitnue?",
"confirm-unsaved": "Unsaved changes will be lost. Continue?",
"alert-success": "Successfully updated your profile!",
"edit-profile": "Edit Profile",
"save": "Save Changes",
Expand Down

0 comments on commit f80b50a

Please sign in to comment.