Skip to content

Commit

Permalink
Merge pull request #335 from animeshdas2000/fix/undefined-url
Browse files Browse the repository at this point in the history
Fix: After trying to delete the last remaining project, it keeps loading and returns undefined in the URL
  • Loading branch information
vmatsiiako authored Feb 21, 2023
2 parents 75eac1b + c65ce14 commit d31b7ae
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 53 deletions.
123 changes: 73 additions & 50 deletions frontend/src/pages/dashboard/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export default function Dashboard() {
const [dropZoneData, setDropZoneData] = useState<SecretDataProps[]>();
const [projectTags, setProjectTags] = useState<Tag[]>([]);

const { hasUnsavedChanges, setHasUnsavedChanges } = useLeaveConfirm({initialValue: false});
const { hasUnsavedChanges, setHasUnsavedChanges } = useLeaveConfirm({ initialValue: false });
const { t } = useTranslation();
const { createNotification } = useNotificationContext();

Expand Down Expand Up @@ -217,6 +217,9 @@ export default function Dashboard() {

useEffect(() => {
(async () => {
if (router.isReady && workspaceId === 'undefined') {
router.push('/noprojects');
}
try {
const tempNumSnapshots = await getProjectSercetSnapshotsCount({
workspaceId
Expand Down Expand Up @@ -314,7 +317,7 @@ export default function Dashboard() {
valueOverride: undefined,
comment: '',
tags: []
},
}
]);
};

Expand Down Expand Up @@ -750,11 +753,13 @@ export default function Dashboard() {
};

const handleOnEnvironmentChange = (envName: string) => {
if(hasUnsavedChanges) {
if (hasUnsavedChanges) {
if (!window.confirm(leaveConfirmDefaultMessage)) return;
}

const selectedWorkspaceEnv = workspaceEnvs.find(({ name }: { name: string }) => envName === name) || {
const selectedWorkspaceEnv = workspaceEnvs.find(
({ name }: { name: string }) => envName === name
) || {
name: 'unknown',
slug: 'unknown',
isWriteDenied: false,
Expand Down Expand Up @@ -843,16 +848,18 @@ export default function Dashboard() {
</div>
<div className="flex flex-row">
<div className="flex justify-start max-w-sm mt-1 mr-2">
{!selectedEnv?.isReadDenied && <Button
text={String(`${numSnapshots} ${t('Commits')}`)}
onButtonPressed={() => {
toggleSidebar('None');
togglePITSidebar(true)
}}
color="mineshaft"
size="md"
icon={faClockRotateLeft}
/>}
{!selectedEnv?.isReadDenied && (
<Button
text={String(`${numSnapshots} ${t('Commits')}`)}
onButtonPressed={() => {
toggleSidebar('None');
togglePITSidebar(true);
}}
color="mineshaft"
size="md"
icon={faClockRotateLeft}
/>
)}
</div>
{(data?.length !== 0 || hasUnsavedChanges) && !snapshotData && (
<div className="flex justify-start max-w-sm mt-1">
Expand Down Expand Up @@ -993,61 +1000,78 @@ export default function Dashboard() {
className="mt-1 max-h-[calc(100vh-280px)] overflow-hidden overflow-y-scroll no-scrollbar no-scrollbar::-webkit-scrollbar border border-mineshaft-600 rounded-md"
>
<div ref={secretsTop} />
<div
className='group flex flex-col items-center bg-mineshaft-800 border-b-2 border-mineshaft-500 duration-100 sticky top-0 z-[60]'
>
<div className="group flex flex-col items-center bg-mineshaft-800 border-b-2 border-mineshaft-500 duration-100 sticky top-0 z-[60]">
<div className="relative flex flex-row justify-between w-full mr-auto max-h-14 items-center">
<div className="w-1/5 border-r border-mineshaft-600 flex flex-row items-center">
<div className='text-transparent text-xs flex items-center justify-center w-12 h-10 cursor-default'>0</div>
<span className='px-2 text-bunker-300 font-semibold'>Key</span>
{!snapshotData && <IconButton
ariaLabel="copy icon"
variant="plain"
className="group relative ml-2"
onClick={() => reorderRows(1)}
>
{sortMethod === 'alphabetical' ? <FontAwesomeIcon icon={faArrowUp} /> : <FontAwesomeIcon icon={faArrowDown} />}
</IconButton>}
<div className="text-transparent text-xs flex items-center justify-center w-12 h-10 cursor-default">
0
</div>
<span className="px-2 text-bunker-300 font-semibold">Key</span>
{!snapshotData && (
<IconButton
ariaLabel="copy icon"
variant="plain"
className="group relative ml-2"
onClick={() => reorderRows(1)}
>
{sortMethod === 'alphabetical' ? (
<FontAwesomeIcon icon={faArrowUp} />
) : (
<FontAwesomeIcon icon={faArrowDown} />
)}
</IconButton>
)}
</div>
<div className="w-5/12 border-r border-mineshaft-600">
<div
className='flex items-center rounded-lg mt-4 md:mt-0 max-h-10'
>
<div className='text-bunker-300 px-2 font-semibold h-10 flex items-center w-7/12'>Value</div>
<div className="flex items-center rounded-lg mt-4 md:mt-0 max-h-10">
<div className="text-bunker-300 px-2 font-semibold h-10 flex items-center w-7/12">
Value
</div>
</div>
</div>
<div className="w-[calc(10%)] border-r border-mineshaft-600">
<div className="flex items-center max-h-16 overflow-hidden">
<div className='text-bunker-300 px-2 font-semibold h-10 flex items-center w-3/12'>Comment</div>
<div className="text-bunker-300 px-2 font-semibold h-10 flex items-center w-3/12">
Comment
</div>
</div>
</div>
<div className="w-2/12">
<div className="flex items-center max-h-16">
<div className='text-bunker-300 px-2 font-semibold h-10 flex items-center w-3/12'>Tags</div>
<div className="text-bunker-300 px-2 font-semibold h-10 flex items-center w-3/12">
Tags
</div>
</div>
</div>
<div
className="w-[1.5rem] h-[2.35rem] ml-auto rounded-md flex flex-row justify-center items-center"
/>
<div className='w-[1.5rem] h-[2.35rem] mr-2 flex items-center justfy-center'>
<div className="w-[1.5rem] h-[2.35rem] ml-auto rounded-md flex flex-row justify-center items-center" />
<div className="w-[1.5rem] h-[2.35rem] mr-2 flex items-center justfy-center">
<div
onKeyDown={() => null}
role="none"
onClick={() => {}}
className="invisible group-hover:visible"
>
<FontAwesomeIcon className="text-bunker-300 hover:text-red pl-2 pr-6 text-lg mt-0.5 invisible" icon={faXmark} />
<FontAwesomeIcon
className="text-bunker-300 hover:text-red pl-2 pr-6 text-lg mt-0.5 invisible"
icon={faXmark}
/>
</div>
</div>
</div>
</div>
<div className="bg-mineshaft-800 rounded-b-md border-bunker-600">
{!snapshotData &&
data
?.filter((row) =>
row.key?.toUpperCase().includes(searchKeys.toUpperCase())
|| row.tags?.map(tag => tag.name).join(" ")?.toUpperCase().includes(searchKeys.toUpperCase())
|| row.comment?.toUpperCase().includes(searchKeys.toUpperCase()))
?.filter(
(row) =>
row.key?.toUpperCase().includes(searchKeys.toUpperCase()) ||
row.tags
?.map((tag) => tag.name)
.join(' ')
?.toUpperCase()
.includes(searchKeys.toUpperCase()) ||
row.comment?.toUpperCase().includes(searchKeys.toUpperCase())
)
.filter((row) => !sharedToHide.includes(row.id))
// .filter((row) => row.value !== undefined)
.map((keyPair) => (
Expand Down Expand Up @@ -1097,15 +1121,15 @@ export default function Dashboard() {
tags={projectTags}
/>
))}
<div className='bg-mineshaft-800 text-sm rounded-t-md hover:bg-mineshaft-700 h-10 w-full flex flex-row items-center border-b-2 border-mineshaft-500 sticky top-0 z-[60]'>
<div className='w-10'/>
<button
<div className="bg-mineshaft-800 text-sm rounded-t-md hover:bg-mineshaft-700 h-10 w-full flex flex-row items-center border-b-2 border-mineshaft-500 sticky top-0 z-[60]">
<div className="w-10" />
<button
type="button"
className='text-bunker-300 relative font-normal h-10 flex items-center w-full cursor-pointer'
className="text-bunker-300 relative font-normal h-10 flex items-center w-full cursor-pointer"
onClick={addRowToBottom}
>
<FontAwesomeIcon icon={faPlus} className='mr-3'/>
<span className='text-sm'>Add Secret</span>
<FontAwesomeIcon icon={faPlus} className="mr-3" />
<span className="text-sm">Add Secret</span>
</button>
</div>
</div>
Expand Down Expand Up @@ -1152,8 +1176,7 @@ export default function Dashboard() {
<SideBar
toggleSidebar={toggleSidebar}
data={data.filter(
(row: SecretDataProps) =>
row.id === sidebarSecretId && row.value !== undefined
(row: SecretDataProps) => row.id === sidebarSecretId && row.value !== undefined
)}
modifyKey={listenChangeKey}
modifyValue={listenChangeValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const ProjectSettingsPage = () => {

const renameWorkspace = useRenameWorkspace();
const toggleAutoCapitalization = useToggleAutoCapitalization();

const deleteWorkspace = useDeleteWorkspace();
// env crud operation
const createWsEnv = useCreateWsEnvironment();
Expand Down Expand Up @@ -97,7 +97,7 @@ export const ProjectSettingsPage = () => {
}
};

const onAutoCapitalizationToggle = async (state: boolean) => {
const onAutoCapitalizationToggle = async (state: boolean) => {
try {
await toggleAutoCapitalization.mutateAsync({
workspaceID,
Expand All @@ -123,6 +123,9 @@ export const ProjectSettingsPage = () => {
await deleteWorkspace.mutateAsync({ workspaceID });
// redirect user to first workspace user is part of
const ws = workspaces.find(({ _id }) => _id !== workspaceID);
if (!ws) {
router.push('/noprojects');
}
router.push(`/dashboard/${ws?._id}`);
createNotification({
text: 'Successfully deleted workspace',
Expand Down Expand Up @@ -247,7 +250,7 @@ export const ProjectSettingsPage = () => {
const res = await createWsTag.mutateAsync({
workspaceID,
tagName: name,
tagSlug: name.replace(" ", "_")
tagSlug: name.replace(' ', '_')
});
createNotification({
text: 'Successfully created a tag',
Expand Down

0 comments on commit d31b7ae

Please sign in to comment.