Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/misc updates #121

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/components/createIdentifierCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@ export function CreateIdentifierCard(
useEffect(() => {
setNameError(props.error);
}, [props.error]);
const onBlurName = () => {
if (!name) {
setNameError(emptyNameError);
} else {
setNameError("");
}
};

const handleRemoveWhiteSpace = () => {
setName(removeWhiteSpace(name));
setNameError("");
};
const onCreateIdentifier = async () => {
const onCreateIdentifier = async (e?: React.SyntheticEvent) => {
e?.preventDefault();
let hasError = false;
if (!name) {
setNameError(emptyNameError);
Expand All @@ -45,6 +39,7 @@ export function CreateIdentifierCard(
{formatMessage({ id: "identifier.error.noWhiteSpace" })}{" "}
<button
className=" underline cursor-pointer"
type="button"
onClick={handleRemoveWhiteSpace}
>
{formatMessage({ id: "action.clickToRemove" })}
Expand All @@ -54,12 +49,18 @@ export function CreateIdentifierCard(
hasError = true;
}

if (!hasError) props.handleCreateIdentifier(name);
if (!hasError) {
setNameError("");
props.handleCreateIdentifier(name);
}
};

return (
<>
<div className=" max-w-xs m-4 flex flex-col gap-y-4">
<form
onSubmit={onCreateIdentifier}
className=" max-w-xs m-4 flex flex-col gap-y-4"
>
<div>
<input
type="text"
Expand All @@ -71,7 +72,6 @@ export function CreateIdentifierCard(
required
value={name}
onChange={(e) => setName(e.target.value)}
onBlur={onBlurName}
/>
{nameError ? (
isValidElement(nameError) ? (
Expand All @@ -83,6 +83,7 @@ export function CreateIdentifierCard(
</div>
<div className=" flex flex-row justify-center mt-2">
<Button
type="submit"
handleClick={onCreateIdentifier}
isLoading={props.isLoading}
className="text-white flex flex-row font-medium rounded-full text-sm px-5 py-2"
Expand All @@ -92,7 +93,7 @@ export function CreateIdentifierCard(
</p>
</Button>
</div>
</div>
</form>
</>
);
}
2 changes: 1 addition & 1 deletion src/components/identifierCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function IdentifierCard({ aid }: IIdentifierCard): JSX.Element {
</span>
</Text>
</div>
<ReactTooltip id={aid.prefix} clickable>
<ReactTooltip id={aid.prefix} clickable delayShow={500}>
<div className="flex flex-row gap-x-1 text-xs">
<p>{aid.prefix}</p>
<button
Expand Down
9 changes: 7 additions & 2 deletions src/components/ui/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { styled } from "styled-components";
import { Loader } from "@components/ui";

interface IButton {
handleClick: () => void;
type?: "button" | "reset" | "submit" | undefined;
handleClick?: () => void;
isLoading?: boolean;
className?: string;
children?: JSX.Element | any;
Expand All @@ -15,7 +16,11 @@ const StyledButton = styled.button`

export function Button(props: IButton): JSX.Element {
return (
<StyledButton onClick={props.handleClick} className={props.className}>
<StyledButton
type={props.type}
onClick={props.handleClick}
className={props.className}
>
{props.isLoading ? <Loader size={4} /> : null}
{props.children}
</StyledButton>
Expand Down
1 change: 1 addition & 0 deletions src/pages/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ chrome.runtime.onMessage.addListener(function (
const resp = await (await fetch(vendorUrl)).json();
if (resp?.agentUrl) {
await configService.setAgentUrl(resp?.agentUrl);
await configService.setHasOnboarded(true)
}
await configService.setData(resp);
if (resp?.icon) {
Expand Down
7 changes: 1 addition & 6 deletions src/pages/popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,9 @@ export default function Popup(): JSX.Element {

useEffect(() => {
checkIfVendorDataExists();
checkInitialConnection();
}, []);

useEffect(() => {
if (vendorData) {
checkInitialConnection();
Copy link
Collaborator Author

@HunnySajid HunnySajid Mar 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rodolfomiranda The error Lance discussed about could be due to this. checkInitialConnection was being called twice. Initially and then after setting vendorData.
There was a race condition between this second call and fetchIdentifiers call. I tried to reproduce that but it is not happening after this fix.

}
}, [vendorData]);

const handleConnect = async (passcode: string) => {
setIsLoading(true);
const agentUrl = await configService.getAgentUrl();
Expand Down
26 changes: 14 additions & 12 deletions src/screens/config/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,6 @@ export function Config(props: any): JSX.Element {

return (
<>
{hasOnboarded ? (
<div className="text-xs flex flex-row justify-between px-2">
<button
onClick={handleBack}
className="cursor-pointer underline font-medium"
>
{formatMessage({ id: "action.back" })}
</button>
</div>
) : (
<></>
)}
<div className="px-4 relative mb-2">
<p className="text-sm font-bold">
{formatMessage({ id: "config.vendorUrl.label" })}
Expand Down Expand Up @@ -170,6 +158,20 @@ export function Config(props: any): JSX.Element {
onSelect={(option) => changeLocale(option.value)}
/>
</div>
{hasOnboarded ? (
<div className="text-xs flex flex-row justify-center px-4 mt-3">
<Button
handleClick={handleBack}
className="text-white flex flex-row focus:outline-none font-medium rounded-full text-sm px-3 py-[2px]"
>
<p className="font-medium text-md">
{formatMessage({ id: "action.save" })}
</p>
</Button>
</div>
) : (
<></>
)}
</>
);
}