Skip to content

Commit

Permalink
Added logged email user on the extension (#42)
Browse files Browse the repository at this point in the history
* added logged email user on the extension

* biome fixes

* added missing props

* biome fixes

* biome fixes
  • Loading branch information
NicoMorenoSirius committed Jun 12, 2024
1 parent f6cf418 commit d4d01af
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions apps/mocksi-lite/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const MOCKSI_AUTH = "mocksi-auth";
export const WebSocketURL = "wss://crowllectordb.onrender.com/ws";
// FIXME: Move to an environment variable
export const SignupURL = "https://nest-auth-ts-merge.onrender.com";
export const STORAGE_KEY = "mocksi-auth";

export enum RecordingState {
UNAUTHORIZED = "UNAUTHORIZED",
Expand Down
4 changes: 3 additions & 1 deletion apps/mocksi-lite/content/ContentApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RecordButton } from "./RecordButton";

interface ContentProps {
isOpen?: boolean;
email: string | null;
}
const recordingLabel = (currentStatus: RecordingState) => {
switch (currentStatus) {
Expand All @@ -28,7 +29,7 @@ const recordingLabel = (currentStatus: RecordingState) => {
}
};

export default function ContentApp({ isOpen }: ContentProps) {
export default function ContentApp({ isOpen, email }: ContentProps) {
const [isDialogOpen, setIsDialogOpen] = useState(isOpen || false);
const initialState = localStorage.getItem(
MOCKSI_RECORDING_STATE,
Expand All @@ -50,6 +51,7 @@ export default function ContentApp({ isOpen }: ContentProps) {
label={recordingLabel(state)}
close={() => setIsDialogOpen(false)}
setState={onChangeState}
email={email}
/>
);
}
Expand Down
7 changes: 5 additions & 2 deletions apps/mocksi-lite/content/Popup/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { logout } from "../../utils";

const Footer = ({ close }: { close: () => void }) => {
const Footer = ({
email,
close,
}: { email: string | null; close: () => void }) => {
return (
<div className={"h-[36px] flex items-center justify-end pr-3"}>
<div className={"text-[13px] text-[#5E5E5E] mr-2"}>jana@mocoso.com</div>
<div className={"text-[13px] text-[#5E5E5E] mr-2"}>{email}</div>
<div
className={"text-[13px] text-[#006C52] underline cursor-pointer"}
onClick={() => {
Expand Down
5 changes: 3 additions & 2 deletions apps/mocksi-lite/content/Popup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ interface PopupProps {
label: string;
setState: (r: RecordingState) => void;
state: RecordingState;
email: string | null;
}

const Popup = ({ label, close, setState, state }: PopupProps) => {
const Popup = ({ label, close, setState, state, email }: PopupProps) => {
const [createForm, setCreateForm] = useState<boolean>(false);

useEffect(() => {
Expand Down Expand Up @@ -50,7 +51,7 @@ const Popup = ({ label, close, setState, state }: PopupProps) => {
{!createForm && (
<div>
<Divider />
<Footer close={close} />
<Footer close={close} email={email} />
</div>
)}
</div>
Expand Down
7 changes: 5 additions & 2 deletions apps/mocksi-lite/content/content.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ReactDOM from "react-dom/client";
import { STORAGE_CHANGE_EVENT } from "../consts";
import { STORAGE_CHANGE_EVENT, STORAGE_KEY } from "../consts";
import ContentApp from "./ContentApp";

let root: ReactDOM.Root;
Expand All @@ -20,7 +20,10 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
root.unmount();
}
root = ReactDOM.createRoot(extensionRoot);
root.render(<ContentApp isOpen={true} />);
chrome.storage.local.get(STORAGE_KEY).then((value) => {
const { email } = JSON.parse(value[STORAGE_KEY] || {});
root.render(<ContentApp isOpen={true} email={email || ""} />);
});
}
sendResponse({ status: "success" });
});
Expand Down

0 comments on commit d4d01af

Please sign in to comment.