diff --git a/app/[locale]/(protected)/admin/management-user/external/detail/[id]/page.tsx b/app/[locale]/(protected)/admin/management-user/external/detail/[id]/page.tsx index e72f21c6..ad272826 100644 --- a/app/[locale]/(protected)/admin/management-user/external/detail/[id]/page.tsx +++ b/app/[locale]/(protected)/admin/management-user/external/detail/[id]/page.tsx @@ -76,9 +76,6 @@ export default function EditUserForm() { }, }); - const passwordVal = form.watch("password"); - const confPasswordVal = form.watch("confirmPassword"); - useEffect(() => { initData(); }, []); diff --git a/app/[locale]/(protected)/admin/management-user/external/edit/[id]/page.tsx b/app/[locale]/(protected)/admin/management-user/external/edit/[id]/page.tsx index 38f63d1f..ed402dc7 100644 --- a/app/[locale]/(protected)/admin/management-user/external/edit/[id]/page.tsx +++ b/app/[locale]/(protected)/admin/management-user/external/edit/[id]/page.tsx @@ -354,7 +354,7 @@ export default function EditUserForm() { rules={["minLength", "specialChar", "number", "capital", "match"]} minLength={8} value={passwordVal || ""} - valueAgain={confPasswordVal} + valueAgain={confPasswordVal || ""} onChange={(isValid) => { form.setValue("isValidPassword", isValid); }} diff --git a/app/[locale]/(protected)/admin/management-user/internal/create/page.tsx b/app/[locale]/(protected)/admin/management-user/internal/create/page.tsx index 7311a6ac..ba4eb2de 100644 --- a/app/[locale]/(protected)/admin/management-user/internal/create/page.tsx +++ b/app/[locale]/(protected)/admin/management-user/internal/create/page.tsx @@ -752,7 +752,7 @@ export default function CreateUserForm() { rules={["minLength", "specialChar", "number", "capital", "match"]} minLength={8} value={passwordVal || ""} - valueAgain={confPasswordVal} + valueAgain={confPasswordVal || ""} onChange={(isValid) => { form.setValue("isValidPassword", isValid); }} diff --git a/app/[locale]/(protected)/admin/management-user/internal/detail/[id]/page.tsx b/app/[locale]/(protected)/admin/management-user/internal/detail/[id]/page.tsx index 4be86550..cec7845c 100644 --- a/app/[locale]/(protected)/admin/management-user/internal/detail/[id]/page.tsx +++ b/app/[locale]/(protected)/admin/management-user/internal/detail/[id]/page.tsx @@ -191,8 +191,6 @@ export default function DetailUserForm() { }, }); - const passwordVal = form.watch("password"); - const confPasswordVal = form.watch("confirmPassword"); const selectedRole = form.watch("role"); useEffect(() => { diff --git a/app/[locale]/(protected)/admin/management-user/internal/edit/[id]/page.tsx b/app/[locale]/(protected)/admin/management-user/internal/edit/[id]/page.tsx index 7cbeb810..d21b5135 100644 --- a/app/[locale]/(protected)/admin/management-user/internal/edit/[id]/page.tsx +++ b/app/[locale]/(protected)/admin/management-user/internal/edit/[id]/page.tsx @@ -757,7 +757,7 @@ export default function EditUserForm() { rules={["minLength", "specialChar", "number", "capital", "match"]} minLength={8} value={passwordVal || ""} - valueAgain={confPasswordVal} + valueAgain={confPasswordVal || ""} onChange={(isValid) => { form.setValue("isValidPassword", isValid); }} diff --git a/app/[locale]/(protected)/admin/settings/category/component/create.tsx b/app/[locale]/(protected)/admin/settings/category/component/create.tsx index 569aaa32..c3a1f512 100644 --- a/app/[locale]/(protected)/admin/settings/category/component/create.tsx +++ b/app/[locale]/(protected)/admin/settings/category/component/create.tsx @@ -125,16 +125,16 @@ export default function CreateCategoryModal() { }); const contentType = form.watch("contentType"); - const isAllContentChecked = listContent.every((item) => - contentType?.includes(item.id) + const isAllContentChecked = contentType && listContent.every((item) => + contentType.includes(item.id) ); const users = form.watch("selectedUser"); - const isAllUserChecked = userList.every((item) => users?.includes(item.id)); + const isAllUserChecked = users && userList.every((item) => users.includes(item.id)); const target = form.watch("publishTo"); - const isAllTargetChecked = publishToList.every((item) => - target?.includes(item.id) + const isAllTargetChecked = target && publishToList.every((item) => + target.includes(item.id) ); const { getRootProps, getInputProps } = useDropzone({ diff --git a/app/[locale]/(protected)/admin/settings/category/component/edit.tsx b/app/[locale]/(protected)/admin/settings/category/component/edit.tsx index aebf2356..249992cd 100644 --- a/app/[locale]/(protected)/admin/settings/category/component/edit.tsx +++ b/app/[locale]/(protected)/admin/settings/category/component/edit.tsx @@ -146,12 +146,12 @@ export default function EditCategoryModal(props: { form.setValue("id", String(data?.id)); form.setValue("title", String(data?.name)); form.setValue("description", String(data?.description)); - form.setValue("contentType", data?.mediaTypes?.split(",")); + form.setValue("contentType", data?.mediaTypes?.split(",") || []); form.setValue( "selectedUser", removeAndReturn(data?.publishedFor, [2, 3, 4]) ); - form.setValue("publishTo", data?.publishedLocation?.split(",")); + form.setValue("publishTo", data?.publishedLocation?.split(",") || []); form.setValue("file", thumbnailLink); setUnitData(filterString(data?.publishedLocationLevel, "under")); @@ -183,16 +183,16 @@ export default function EditCategoryModal(props: { } const contentType = form.watch("contentType"); - const isAllContentChecked = listContent.every((item) => - contentType?.includes(item.id) + const isAllContentChecked = contentType && listContent.every((item) => + contentType.includes(item.id) ); const users = form.watch("selectedUser"); - const isAllUserChecked = userList.every((item) => users?.includes(item.id)); + const isAllUserChecked = users && userList.every((item) => users.includes(item.id)); const target = form.watch("publishTo"); - const isAllTargetChecked = publishToList.every((item) => - target?.includes(item.id) + const isAllTargetChecked = target && publishToList.every((item) => + target.includes(item.id) ); useEffect(() => { diff --git a/app/[locale]/(protected)/admin/settings/category/component/unit-mapping.tsx b/app/[locale]/(protected)/admin/settings/category/component/unit-mapping.tsx index 34f037d6..109583ed 100644 --- a/app/[locale]/(protected)/admin/settings/category/component/unit-mapping.tsx +++ b/app/[locale]/(protected)/admin/settings/category/component/unit-mapping.tsx @@ -68,11 +68,11 @@ export function UnitMapping(props: { const unitType = form.watch("items"); - const isAllUnitChecked = unitList.every((item) => - unitType?.includes(String(item.id)) + const isAllUnitChecked = unitType && unitList.every((item) => + unitType.includes(String(item.id)) ); - const isAllSatkerChecked = satkerList.every((item) => - unitType?.includes(String(item.id)) + const isAllSatkerChecked = unitType && satkerList.every((item) => + unitType.includes(String(item.id)) ); const setupUnit = (data: UnitType[]) => { diff --git a/app/[locale]/(protected)/admin/settings/faq/component/create.tsx b/app/[locale]/(protected)/admin/settings/faq/component/create.tsx index 504d9fa5..c2de04e6 100644 --- a/app/[locale]/(protected)/admin/settings/faq/component/create.tsx +++ b/app/[locale]/(protected)/admin/settings/faq/component/create.tsx @@ -91,8 +91,8 @@ export default function CreateFAQModal() { }); const target = form.watch("publishTo"); - const isAllTargetChecked = publishToList.every((item) => - target?.includes(item.id) + const isAllTargetChecked = target && publishToList.every((item) => + target.includes(item.id) ); const onSubmit = async (data: z.infer) => { diff --git a/app/[locale]/(protected)/contributor/agenda-setting/unit-mapping.tsx b/app/[locale]/(protected)/contributor/agenda-setting/unit-mapping.tsx index aea59fb3..622519a7 100644 --- a/app/[locale]/(protected)/contributor/agenda-setting/unit-mapping.tsx +++ b/app/[locale]/(protected)/contributor/agenda-setting/unit-mapping.tsx @@ -74,11 +74,11 @@ export function UnitMapping(props: { const unitType = form.watch("items"); - const isAllUnitChecked = unitList.every((item) => - unitType?.includes(String(item.id)) + const isAllUnitChecked = unitType && unitList.every((item) => + unitType.includes(String(item.id)) ); - const isAllSatkerChecked = satkerList.every((item) => - unitType?.includes(String(item.id)) + const isAllSatkerChecked = unitType && satkerList.every((item) => + unitType.includes(String(item.id)) ); const isAllPolresChecked = polresList.every((item) => unitType?.includes(String(item.id)) diff --git a/app/[locale]/(protected)/contributor/content/image/components/columns.tsx b/app/[locale]/(protected)/contributor/content/image/components/columns.tsx index 18b9837b..296424d7 100644 --- a/app/[locale]/(protected)/contributor/content/image/components/columns.tsx +++ b/app/[locale]/(protected)/contributor/content/image/components/columns.tsx @@ -132,29 +132,36 @@ const useTableColumns = () => { accessorKey: "statusName", header: "Status", cell: ({ row }) => { - const statusColors: Record = { - diterima: "bg-green-100 text-green-600", - "menunggu review": "bg-orange-100 text-orange-600", + const statusId = Number(row.original?.statusId); + const reviewedAtLevel = row.original?.reviewedAtLevel || ""; + const creatorGroupLevelId = Number(row.original?.creatorGroupLevelId); + const needApprovalFromLevel = Number( + row.original?.needApprovalFromLevel + ); + + const userHasReviewed = reviewedAtLevel.includes(`:${userLevelId}:`); + const isCreator = creatorGroupLevelId === Number(userLevelId); + + const isWaitingForReview = + statusId === 2 && !userHasReviewed && !isCreator; + + const isApprovalNeeded = + statusId === 1 && needApprovalFromLevel === Number(userLevelId); + + const label = + isWaitingForReview || isApprovalNeeded + ? "Menunggu Review" + : statusId === 2 + ? "Diterima" + : row.original?.statusName; + + const colors: Record = { + "Menunggu Review": "bg-orange-100 text-orange-600", + Diterima: "bg-green-100 text-green-600", + default: "bg-red-200 text-red-600", }; - const colors = [ - "bg-orange-100 text-orange-600", - "bg-orange-100 text-orange-600", - "bg-green-100 text-green-600", - "bg-blue-100 text-blue-600", - "bg-red-200 text-red-600", - ]; - - const status = - Number(row.original?.statusId) == 2 && - row.original?.reviewedAtLevel !== null && - !row.original?.reviewedAtLevel?.includes(`:${userLevelId}:`) && - Number(row.original?.creatorGroupLevelId) != Number(userLevelId) - ? "1" - : row.original?.statusId; - const statusStyles = - colors[Number(status)] || "bg-red-200 text-red-600"; - // const statusStyles = statusColors[status] || "bg-red-200 text-red-600"; + const statusStyles = colors[label] || colors.default; return ( { statusStyles )} > - {(Number(row.original?.statusId) == 2 && - !row.original?.reviewedAtLevel !== null && - !row.original?.reviewedAtLevel?.includes( - `:${Number(userLevelId)}:` - ) && - Number(row.original?.creatorGroupLevelId) != - Number(userLevelId)) || - (Number(row.original?.statusId) == 1 && - Number(row.original?.needApprovalFromLevel) == - Number(userLevelId)) - ? "Menunggu Review" - : row.original?.statusName}{" "} + {label} ); }, diff --git a/app/[locale]/(protected)/curator/task-plan/mediahub/create-daily/detail/[id]/page.tsx b/app/[locale]/(protected)/curator/task-plan/mediahub/create-daily/detail/[id]/page.tsx index 253f3137..bc3e5de7 100644 --- a/app/[locale]/(protected)/curator/task-plan/mediahub/create-daily/detail/[id]/page.tsx +++ b/app/[locale]/(protected)/curator/task-plan/mediahub/create-daily/detail/[id]/page.tsx @@ -281,11 +281,11 @@ export default function DetailDaily() { const output = form.watch("output"); - const isAllChecked = items.every((item) => output?.includes(item.id)); + const isAllChecked = output && items.every((item) => output.includes(item.id)); const unit = form.watch("unit"); - const isAllUnitChecked = units.every((item) => unit?.includes(item.id)); + const isAllUnitChecked = unit && units.every((item) => unit.includes(item.id)); const handleAllCheckedChange = (checked: boolean | string) => { if (checked) { @@ -318,11 +318,11 @@ export default function DetailDaily() { const handleUnitCheckedChange = (id: string, checked: boolean | string) => { if (checked) { - form.setValue("unit", [...unit, id]); + form.setValue("unit", [...(unit ?? []), id]); } else { if (id == "2") { const temp = []; - for (const element of unit) { + for (const element of unit ?? []) { if (element == "1") { temp.push("1"); } @@ -331,7 +331,7 @@ export default function DetailDaily() { } else { form.setValue( "unit", - unit.filter((value) => value !== id) + (unit ?? []).filter((value) => value !== id) ); } } @@ -542,14 +542,14 @@ export default function DetailDaily() { id={list.id} name={`all${list.id}`} checked={ - unit.includes("2") + unit?.includes("2") ?? false ? true : !!selected[list.id] } onCheckedChange={() => handleParentChange(list.id) } - disabled={unit.includes("2")} + disabled={unit?.includes("2") ?? false} />