Skip to content

Commit

Permalink
Solving commentaries on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
diego-morales-flores-1996 committed Jun 5, 2024
1 parent 22212ae commit 91af2b4
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const polygonStatusLabels = [
];

const SitePolygonStatus = ({ statusLabel }: { statusLabel: string }) => {
let status = statusLabel === "Unkown" ? "Planting in progress" : statusLabel;
const status = statusLabel === "Unknown" ? "Planting in progress" : statusLabel;
const statusIndex = polygonStatusLabels.findIndex(({ label }) => label === status);
const progress = statusIndex === -1 ? 0 : statusIndex * 25;
return <StepProgressbar color="primary" value={progress} labels={polygonStatusLabels} labelVariant="text-10" />;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import { useT } from "@transifex/react";

import Text from "@/components/elements/Text/Text";

const StatusLeyend = () => {
const StatusLegend = () => {
const t = useT();
return (
<div className="flex flex-col px-2">
<Text variant="text-16-bold" className="text-darkCustom">
Status Legend
{t("Status Legend")}
</Text>
<div>
<Text variant="text-14-semibold" className="flex items-center gap-2 py-2 text-darkCustom">
<div className="aspect-square h-3 w-3 rounded-sm bg-pinkCustom" /> Status Legend
<div className="aspect-square h-3 w-3 rounded-sm bg-pinkCustom" /> {t("Status Legend")}
</Text>
<Text variant="text-14-semibold" className="flex items-center gap-2 py-2 text-darkCustom">
<div className="aspect-square h-3 w-3 rounded-sm bg-blue" /> Submitted
<div className="aspect-square h-3 w-3 rounded-sm bg-blue" /> {t("Submitted")}
</Text>
<Text variant="text-14-semibold" className="flex items-center gap-2 py-2 text-darkCustom">
<div className="aspect-square h-3 w-3 rounded-sm bg-green" /> Approved
<div className="aspect-square h-3 w-3 rounded-sm bg-green" /> {t("Approved")}
</Text>
<Text variant="text-14-semibold" className="flex items-center gap-2 py-2 text-darkCustom">
<div className="aspect-square h-3 w-3 rounded-sm bg-tertiary-600" /> Needs More Info
<div className="aspect-square h-3 w-3 rounded-sm bg-tertiary-600" /> {t("Needs More Info")}
</Text>
</div>
</div>
);
};

export default StatusLeyend;
export default StatusLegend;
2 changes: 1 addition & 1 deletion src/components/elements/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Accordion = ({
<Disclosure
as="div"
defaultOpen={defaultOpen}
className={classNames(`${className}`, {
className={classNames(className, {
"rounded-lg border-2 border-neutral-100 shadow": variant === "default" || variant === "secondary"
})}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ const GoalProgressCard: FC<GoalProgressCardProps> = ({
labelValue,
...rest
}) => {
const value = _val || 0;
const valueText = value;
const value = _val ?? 0;

// Calculates percentage and clamps between 0 and 100
const progressValue = !limit ? 0 : Math.min(Math.max((value / limit) * 100, 0), 100);
Expand All @@ -43,7 +42,7 @@ const GoalProgressCard: FC<GoalProgressCardProps> = ({
{label}
</Text>
<Text variant="text-24-bold" className="flex w-full items-baseline">
{valueText}&nbsp;
{value}&nbsp;
<When condition={!!limit}>
<Text variant="text-16-light">of {limit}</Text>
</When>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface ItemMonitoringCardsProps
className?: string;
img?: IconNames;
type?: "graph" | "map" | "graph-button";
leyends?: LeyendItemMonitoringCardsProps[];
legends?: LeyendItemMonitoringCardsProps[];
}

const ItemMonitoringCards = ({
Expand All @@ -42,7 +42,7 @@ const ItemMonitoringCards = ({
type,
img,
item,
leyends,
legends,
key,
...props
}: ItemMonitoringCardsProps) => {
Expand Down Expand Up @@ -109,16 +109,15 @@ const ItemMonitoringCards = ({
/>
</div>
</When>
<When condition={!!leyends}>
<When condition={!!legends}>
<div className="mt-2 flex flex-wrap justify-center gap-x-2">
{leyends &&
leyends.map((leyend: any, index: number) => (
<Text as="span" key={index} variant="text-8" className="flex items-center whitespace-nowrap">
<div className={`h-1 w-1 lg:h-2 lg:w-2 ${leyend.color} rounded-full`} />
&nbsp;
{leyend.title}
</Text>
))}
{legends?.map((legend: any, index: number) => (
<Text as="span" key={index} variant="text-8" className="flex items-center whitespace-nowrap">
<div className={`h-1 w-1 lg:h-2 lg:w-2 ${legend.color} rounded-full`} />
&nbsp;
{legend.title}
</Text>
))}
</div>
</When>
</div>
Expand Down
27 changes: 14 additions & 13 deletions src/components/elements/Cards/UserRoleCard/UserRoleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,19 @@ const UserRoleCard: React.FC<UserRoleCardProps> = ({
)
}
];
const displayOption = options?.find(m => {
if (selectedOption === null) {
return false;
} else {
if (title === "I’m a Government Official") {
return m.country_slug === selectedOption;
} else {
return m.data.label === selectedOption;
}
}
});
const diplayTitle = displayOption ? displayOption.data.label : "";

const displayOptions =
selectedOption == null
? null
: options?.find(m => {
if (title === "I’m a Government Official") {
return m.country_slug === selectedOption;
} else {
return m.data.label === selectedOption;
}
});

const diplayTitle = displayOptions ? displayOptions.data.label : "";

return (
<article
Expand Down Expand Up @@ -81,7 +82,7 @@ const UserRoleCard: React.FC<UserRoleCardProps> = ({
selectedOption={selectedOption}
>
<Text variant="text-12-bold" className="text-primary">
{titleOptions || t("Select Fund")}
{titleOptions ?? t("Select Fund")}
{diplayTitle ? `: ${diplayTitle}` : ""}
</Text>
</Menu>
Expand Down
21 changes: 5 additions & 16 deletions src/components/elements/Inputs/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { formatOptionsList, statusColor } from "@/utils/options";
import Status from "../../Status/Status";
import Text from "../../Text/Text";
import Checkbox from "../Checkbox/Checkbox";
import { COLOR_MAP } from "./constants/colorMap";

export interface DropdownProps {
customName?: string;
Expand Down Expand Up @@ -82,7 +83,7 @@ const Dropdown = (props: PropsWithChildren<DropdownProps>) => {
updateControl.current++;
}
}, [props.value, props.options, props.hasOtherOptions]);
const onChange = async (value: OptionValue | OptionValue[], _otherValue?: string) => {
const onChange = (value: OptionValue | OptionValue[], _otherValue?: string) => {
let otherStr = typeof _otherValue === "string" ? _otherValue : otherValue;
if (Array.isArray(value)) {
if (props.onChangeConfirm) {
Expand Down Expand Up @@ -135,18 +136,6 @@ const Dropdown = (props: PropsWithChildren<DropdownProps>) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [otherIsSelected, otherValue, t]);

const getColorStatus = (option: string): string => {
const colorMap: { [key: string]: string } = {
approved: "bg-green",
submitted: "bg-blue",
draft: "bg-pinkCustom",
"Under Review": "bg-tertiary-600",
"Needs More Info": "bg-tertiary-600"
};

return colorMap[option] ?? "";
};

return (
<div className={tw("space-y-2", props.containerClassName)}>
<Listbox value={selected} defaultValue={selected} onChange={onChange} multiple={props.multiSelect}>
Expand Down Expand Up @@ -179,9 +168,9 @@ const Dropdown = (props: PropsWithChildren<DropdownProps>) => {
<div className="flex items-center gap-2">
<When condition={options?.[0]?.meta != null}>
<div
className={`min-h-[8px] min-w-[8px] rounded-full ${getColorStatus(
statusColor(options, toArray<any>(value)) ?? ""
)}`}
className={`min-h-[8px] min-w-[8px] rounded-full ${
COLOR_MAP[statusColor(options, toArray<any>(value)) ?? ""]
}`}
/>
</When>
<Text variant={props.inputVariant ?? "text-14-light"} className="w-full line-clamp-1">
Expand Down
7 changes: 7 additions & 0 deletions src/components/elements/Inputs/Dropdown/constants/colorMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const COLOR_MAP: { [key: string]: string } = {
approved: "bg-green",
submitted: "bg-blue",
draft: "bg-pinkCustom",
"Under Review": "bg-tertiary-600",
"Needs More Info": "bg-tertiary-600"
};
32 changes: 12 additions & 20 deletions src/components/elements/Inputs/FileInput/FilePreviewCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { useFileSize } from "@/hooks/useFileSize";
import { UploadedFile } from "@/types/common";

import Text from "../../Text/Text";
import { SUBTITLE_MAP_ON_FAILED } from "./constants/subtitleMapOnFailed";
import { SUBTITLE_MAP_ON_UPLOADED } from "./constants/subtitleMapOnUploaded";
import { SUBTITLE_MAP_ON_UPLOADING } from "./constants/subtitleMapOnUploading";
import { FilePreviewCardVariant, VARIANT_FILE_PREVIEW_CARD_DEFAULT } from "./FileInputVariants";

export interface FilePreviewCardProps {
Expand All @@ -38,6 +41,7 @@ const FilePreviewCard = ({

onPrivateChange?.(file, checked);
};
const t = useT();

return (
<div className={tw(variant.fileWrapper, className)}>
Expand Down Expand Up @@ -72,7 +76,7 @@ const FilePreviewCard = ({
<IconButton
type="button"
onClick={() => onDelete?.(file)}
aria-label="Delete button"
aria-label={t("Delete button")}
iconProps={{
name:
variant.type === "image" || variant.type === "geoFile" ? IconNames.TRASH_PA : IconNames.TRASH_CIRCLE,
Expand All @@ -95,7 +99,7 @@ const FilePreviewCard = ({
"text-red": !fileStatus
})}
>
{fileStatus ? "GeoTagged Verified" : "Not Verified"}
{fileStatus ? t("GeoTagged Verified") : t("Not Verified")}
</Text>
</div>
</When>
Expand All @@ -118,14 +122,10 @@ interface UploadingProps {
const Uploading = ({ title, file, variant }: UploadingProps) => {
const t = useT();
const { format } = useFileSize();
const subtitleMap = {
image: "Image is being uploaded.",
geoFile: "Data is being uploaded."
};

let subtitle;
if (variant.type !== undefined && subtitleMap[variant.type] !== undefined) {
subtitle = subtitleMap[variant.type];
if (variant.type !== undefined && SUBTITLE_MAP_ON_UPLOADING[variant.type] !== undefined) {
subtitle = SUBTITLE_MAP_ON_UPLOADING[variant.type];
} else {
subtitle = "Uploading document ...";
}
Expand All @@ -149,14 +149,10 @@ interface UploadedProps extends UploadingProps {
const Uploaded = ({ title, file, showPrivateCheckbox, onPrivateChange, variant }: UploadedProps) => {
const t = useT();
const { format } = useFileSize();
const subtitleMap = {
image: "Image uploaded successfully!",
geoFile: "Data uploaded successfully!"
};

let subtitle;
if (variant.type !== undefined && subtitleMap[variant.type] !== undefined) {
subtitle = subtitleMap[variant.type];
if (variant.type !== undefined && SUBTITLE_MAP_ON_UPLOADED[variant.type] !== undefined) {
subtitle = SUBTITLE_MAP_ON_UPLOADED[variant.type];
} else {
subtitle = "Document Uploaded";
}
Expand All @@ -183,14 +179,10 @@ interface FailedContentProps {

const Failed = ({ title, errorMessage: errorState, variant }: FailedContentProps) => {
const t = useT();
const subtitleMap = {
image: "Error uploading image.",
geoFile: "Error uploading data."
};

let errorMessage;
if (variant.type !== undefined && subtitleMap[variant.type] !== undefined) {
errorMessage = subtitleMap[variant.type];
if (variant.type !== undefined && SUBTITLE_MAP_ON_FAILED[variant.type] !== undefined) {
errorMessage = SUBTITLE_MAP_ON_FAILED[variant.type];
} else {
errorMessage = "Upload Failed";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const SUBTITLE_MAP_ON_FAILED = {
image: "Error uploading image.",
geoFile: "Error uploading data."
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const SUBTITLE_MAP_ON_UPLOADED = {
image: "Image uploaded successfully!",
geoFile: "Data uploaded successfully!"
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const SUBTITLE_MAP_ON_UPLOADING = {
image: "Image is being uploaded.",
geoFile: "Data is being uploaded."
};

0 comments on commit 91af2b4

Please sign in to comment.