Skip to content

Commit

Permalink
fix: Allow setting demo mode creds when demo mode is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Mar 26, 2024
1 parent 4fa4a14 commit eff2f83
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apps/web/components/DemoModeBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function DemoModeBanner() {
return (
<div className="h-min w-full rounded bg-yellow-100 px-4 py-2 text-center">
<div className="h-min w-full rounded bg-yellow-100 px-4 py-2 text-center text-black">
Demo mode is on. All modifications are disabled.
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions apps/web/components/dashboard/bookmarks/AddToListModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ export default function AddToListModal({
{l.icon} {l.name}
</SelectItem>
))}
{lists && lists.lists.length == 0 && (
<SelectItem value="nolist" disabled>
You don&apos;t currently have any lists.
</SelectItem>
)}
</SelectGroup>
</SelectContent>
</Select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) {
const { toast } = useToast();
const linkId = bookmark.id;

const demoMode = useClientConfig().demoMode;
const demoMode = !!useClientConfig().demoMode;

const { setOpen: setTagModalIsOpen, content: tagModal } =
useTagModel(bookmark);
Expand Down
37 changes: 18 additions & 19 deletions apps/web/components/dashboard/bookmarks/TagsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,26 @@ interface EditableTag {
}

export function TagsEditor({ bookmark }: { bookmark: ZBookmark }) {
const demoMode = useClientConfig().demoMode;
const demoMode = !!useClientConfig().demoMode;
const bookmarkInvalidationFunction =
api.useUtils().bookmarks.getBookmark.invalidate;

const { mutate, isPending: isMutating } =
api.bookmarks.updateTags.useMutation({
onSuccess: () => {
toast({
description: "Tags has been updated!",
});
bookmarkInvalidationFunction({ bookmarkId: bookmark.id });
// TODO(bug) Invalidate the tag views as well
},
onError: () => {
toast({
variant: "destructive",
title: "Something went wrong",
description: "There was a problem with your request.",
});
},
});
const { mutate } = api.bookmarks.updateTags.useMutation({
onSuccess: () => {
toast({
description: "Tags has been updated!",
});
bookmarkInvalidationFunction({ bookmarkId: bookmark.id });
// TODO(bug) Invalidate the tag views as well
},
onError: () => {
toast({
variant: "destructive",
title: "Something went wrong",
description: "There was a problem with your request.",
});
},
});

const { data: existingTags, isLoading: isExistingTagsLoading } =
api.tags.list.useQuery();
Expand Down Expand Up @@ -98,7 +97,7 @@ export function TagsEditor({ bookmark }: { bookmark: ZBookmark }) {
isMulti
closeMenuOnSelect={false}
isClearable={false}
isLoading={isExistingTagsLoading || isMutating}
isLoading={isExistingTagsLoading}
theme={(theme) => ({
...theme,
// This color scheme doesn't support disabled options.
Expand Down
9 changes: 9 additions & 0 deletions apps/web/components/signin/SignInForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { getProviders } from "next-auth/react";

import serverConfig from "@hoarder/shared/config";

import CredentialsForm from "./CredentialsForm";
import SignInProviderButton from "./SignInProviderButton";

Expand All @@ -15,6 +17,13 @@ export default async function SignInForm() {

return (
<div className="flex flex-col items-center space-y-2">
{serverConfig.demoMode && (
<div className="mb-1 w-full items-start space-y-1 rounded bg-accent p-3">
<p className="text-center font-bold">Demo Mode</p>
<p>Email: {serverConfig.demoMode.email} </p>
<p>Password: {serverConfig.demoMode.password} </p>
</div>
)}
<CredentialsForm />

{providerValues && providerValues.length > 0 && (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/lib/clientConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createContext, useContext } from "react";
import type { ClientConfig } from "@hoarder/shared/config";

export const ClientConfigCtx = createContext<ClientConfig>({
demoMode: false,
demoMode: undefined,
auth: {
disableSignups: false,
},
Expand Down
5 changes: 4 additions & 1 deletion packages/shared/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const serverConfig = {
}
: undefined,
logLevel: process.env.LOG_LEVEL ?? "debug",
demoMode: (process.env.DEMO_MODE ?? "false") == "true",
demoMode: (process.env.DEMO_MODE ?? "false") == "true" ? {
email: process.env.DEMO_MODE_EMAIL,
password: process.env.DEMO_MODE_PASSWORD,
}: undefined,
dataDir: process.env.DATA_DIR ?? "",
};

Expand Down

0 comments on commit eff2f83

Please sign in to comment.