Skip to content

Commit

Permalink
fix-redirect-when-already-in-org (#578)
Browse files Browse the repository at this point in the history
## What does this PR do?

<!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. -->

Fixes # (issue)

_If there is not an issue for this, please create one first. This is used to tracking purposes and also helps use understand why this PR exists_

<!-- If there isn't an issue for this PR, please re-review our Contributing Guide and create an issue -->

## Type of change

<!-- Please mark the relevant points by using [x] -->

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] Chore (refactoring code, technical debt, workflow improvements)
- [ ] Enhancement (small improvements)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

## Checklist

<!-- We're starting to get more and more contributions. Please help us making this efficient for all of us and go through this checklist. Please tick off what you did  -->

### Required

- [ ] Read [Contributing Guide](https://github.com/un/inbox/blob/main/CONTRIBUTING.md)
- [x] Self-reviewed my own code
- [x] Tested my code in a local environment
- [ ] Commented on my code in hard-to-understand areas
- [ ] Checked for warnings, there are none
- [ ] Removed all `console.logs`
- [ ] Merged the latest changes from main onto my branch with `git pull origin main`
- [ ] My changes don't cause any responsiveness issues

### Appreciated

- [ ] If a UI change was made: Added a screen recording or screenshots to this PR
- [ ] Updated the UnInbox Docs if changes were necessary
  • Loading branch information
benjaminshafii authored Jul 18, 2024
1 parent b50a94f commit f730f55
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions apps/web/src/app/join/profile/_components/profile-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useEffect, useState } from 'react';
import { cn, generateAvatarUrl } from '@/src/lib/utils';
import useLoading from '@/src/hooks/use-loading';
import { Camera, Checks, SkipForward } from '@phosphor-icons/react';
import { useRouter } from 'next/navigation';
import { useRouter, useSearchParams } from 'next/navigation';
import { toast } from 'sonner';
import useAwaitableModal from '@/src/hooks/use-awaitable-modal';
import { Input } from '@/src/components/shadcn-ui/input';
Expand All @@ -31,6 +31,8 @@ export function ProfileCard({ orgData, wasInvited }: ProfileCardProps) {
);

const router = useRouter();
const query = useSearchParams();
const orgShortCode = query.get('org');

const {
error: avatarError,
Expand Down Expand Up @@ -62,7 +64,6 @@ export function ProfileCard({ orgData, wasInvited }: ProfileCardProps) {
profilePublicId: orgData.profile.publicId,
title: orgData.profile.title ?? ''
});
router.push('/');
});

useEffect(() => {
Expand All @@ -71,6 +72,14 @@ export function ProfileCard({ orgData, wasInvited }: ProfileCardProps) {
}
}, [saveError]);

const handleSkip = () => {
router.push(`/${orgShortCode}`);
};
const handleSave = () => {
saveProfile({ clearData: true, clearError: true });
router.push(`/${orgShortCode}`);
};

return (
<div className="mx-auto flex w-full max-w-[560px] flex-col gap-3 px-4">
<div className="mt-3 text-lg font-bold">
Expand Down Expand Up @@ -135,15 +144,15 @@ export function ProfileCard({ orgData, wasInvited }: ProfileCardProps) {
<Button
className="flex-1"
variant="secondary"
onClick={() => router.push('/')}>
onClick={handleSkip}>
Skip
<SkipForward size={16} />
</Button>
<Button
className="flex-1"
disabled={!firstNameValue || !lastNameValue}
loading={saveLoading}
onClick={() => saveProfile({ clearData: true, clearError: true })}>
onClick={handleSave}>
Next
<Checks size={16} />
</Button>
Expand Down

0 comments on commit f730f55

Please sign in to comment.