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

LCFS-1453: Legal name of transaction partner #1489

Merged
merged 2 commits into from
Dec 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useGetAllocationAgreements,
useSaveAllocationAgreement
} from '@/hooks/useAllocationAgreement'
import { useCurrentUser } from '@/hooks/useCurrentUser'
import { v4 as uuid } from 'uuid'
import * as ROUTES from '@/constants/routes/routes.js'
import { DEFAULT_CI_FUEL } from '@/constants/common'
Expand All @@ -31,6 +32,7 @@ export const AddEditAllocationAgreements = () => {
const params = useParams()
const { complianceReportId, compliancePeriod } = params
const navigate = useNavigate()
const { data: currentUser } = useCurrentUser()

const {
data: optionsData,
Expand Down Expand Up @@ -117,9 +119,9 @@ export const AddEditAllocationAgreements = () => {
)

useEffect(() => {
const updatedColumnDefs = allocationAgreementColDefs(optionsData, errors)
const updatedColumnDefs = allocationAgreementColDefs(optionsData, errors, currentUser)
setColumnDefs(updatedColumnDefs)
}, [errors, optionsData])
}, [errors, optionsData, currentUser])

useEffect(() => {
if (
Expand Down Expand Up @@ -173,6 +175,18 @@ export const AddEditAllocationAgreements = () => {
async (params) => {
if (params.oldValue === params.newValue) return

// User cannot select their own organization as the transaction partner
if (params.colDef.field === 'transactionPartner') {
if (params.newValue === currentUser.organization.name) {
alertRef.current?.triggerAlert({
message: 'You cannot select your own organization as the transaction partner.',
severity: 'error'
})
params.node.setDataValue('transactionPartner', '')
return
}
}

const isValid = validate(
params,
(value) => {
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/views/AllocationAgreements/_schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {

export const PROVISION_APPROVED_FUEL_CODE = 'Fuel code - section 19 (b) (i)'

export const allocationAgreementColDefs = (optionsData, errors) => [
export const allocationAgreementColDefs = (optionsData, errors, currentUser) => [
validation,
actions({
enableDuplicate: false,
Expand Down Expand Up @@ -89,8 +89,11 @@ export const allocationAgreementColDefs = (optionsData, errors) => [
let path = apiRoutes.organizationSearch
path += 'org_name=' + queryKey[1]
const response = await client.get(path)
params.node.data.apiDataCache = response.data
return response.data
const filteredData = response.data.filter(
(org) => org.name !== currentUser.organization.name
)
params.node.data.apiDataCache = filteredData
return filteredData
},
title: 'transactionPartner',
api: params.api,
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/views/NotionalTransfers/AddEditNotionalTransfers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useGetAllNotionalTransfers,
useSaveNotionalTransfer
} from '@/hooks/useNotionalTransfer'
import { useCurrentUser } from '@/hooks/useCurrentUser'
import { v4 as uuid } from 'uuid'
import { BCGridEditor } from '@/components/BCDataGrid/BCGridEditor'
import { useApiService } from '@/services/useApiService'
Expand All @@ -37,6 +38,7 @@ export const AddEditNotionalTransfers = () => {
useGetAllNotionalTransfers(complianceReportId)
const { mutateAsync: saveRow } = useSaveNotionalTransfer()
const navigate = useNavigate()
const { data: currentUser } = useCurrentUser()

useEffect(() => {
if (location?.state?.message) {
Expand Down Expand Up @@ -115,6 +117,18 @@ export const AddEditNotionalTransfers = () => {
async (params) => {
if (params.oldValue === params.newValue) return

// User cannot select their own organization as the transaction partner
if (params.colDef.field === 'legalName') {
if (params.newValue === currentUser.organization.name) {
alertRef.current?.triggerAlert({
message: 'You cannot select your own organization as the transaction partner.',
severity: 'error'
})
params.node.setDataValue('legalName', '')
return
}
}

const isValid = validate(
params,
(value) => {
Expand Down Expand Up @@ -223,10 +237,10 @@ export const AddEditNotionalTransfers = () => {

useEffect(() => {
if (!optionsLoading) {
const updatedColumnDefs = notionalTransferColDefs(optionsData, errors)
const updatedColumnDefs = notionalTransferColDefs(optionsData, errors, currentUser)
setColumnDefs(updatedColumnDefs)
}
}, [errors, optionsData, optionsLoading])
}, [errors, optionsData, optionsLoading, currentUser])

const handleNavigateBack = useCallback(() => {
navigate(
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/views/NotionalTransfers/_schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { formatNumberWithCommas as valueFormatter } from '@/utils/formatters'
import { apiRoutes } from '@/constants/routes'
import { StandardCellErrors } from '@/utils/grid/errorRenderers'

export const notionalTransferColDefs = (optionsData, errors) => [
export const notionalTransferColDefs = (optionsData, errors, currentUser) => [
validation,
actions({
enableDuplicate: false,
Expand Down Expand Up @@ -45,8 +45,11 @@ export const notionalTransferColDefs = (optionsData, errors) => [
let path = apiRoutes.organizationSearch
path += 'org_name=' + queryKey[1]
const response = await client.get(path)
params.node.data.apiDataCache = response.data
return response.data
const filteredData = response.data.filter(
(org) => org.name !== currentUser.organization.name
)
params.node.data.apiDataCache = filteredData
return filteredData
},
title: 'legalName',
api: params.api
Expand Down