Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion app/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export const FONT_FAMILY_HEADER = 'Montserrat';
// This should not be the same as OperationType.
export type DrefStatus = components<'read'>['schemas']['DrefDrefStatusEnumKey'];
// const DREF_STATUS_COMPLETED = 1 satisfies DrefStatus;
export const DREF_STATUS_IN_PROGRESS = 0 satisfies DrefStatus;
export const DREF_STATUS_DRAFT = 1 satisfies DrefStatus;
export const DREF_STATUS_APPROVED = 4 satisfies DrefStatus;

export type TypeOfDrefEnum = components<'read'>['schemas']['DrefDrefDrefTypeEnumKey'];
export const DREF_TYPE_IMMINENT = 0 satisfies TypeOfDrefEnum;
Expand Down
5 changes: 4 additions & 1 deletion app/src/views/AccountMyFormsDref/ActiveDrefTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import useUserMe from '#hooks/domain/useUserMe';
import useFilterState from '#hooks/useFilterState';
import {
DREF_STATUS_APPROVED,
DREF_TYPE_LOAN,
type TypeOfDrefEnum,
} from '#utils/constants';
Expand Down Expand Up @@ -230,13 +231,15 @@ function ActiveDrefTable(props: Props) {

const {
unpublished_op_update_count,
is_published,
status,
has_ops_update,
has_final_report,
country_details,
is_dref_imminent_v2,
} = originalDref;

const is_published = status === DREF_STATUS_APPROVED;

const canAddOpsUpdate = (is_published ?? false)
&& (applicationType === 'DREF' || applicationType === 'OPS_UPDATE')
&& !has_final_report
Expand Down
16 changes: 8 additions & 8 deletions app/src/views/AccountMyFormsDref/DrefTableActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Link from '#components/Link';
import useAlert from '#hooks/useAlert';
import useRouting from '#hooks/useRouting';
import {
DREF_STATUS_IN_PROGRESS,
DREF_STATUS_DRAFT,
DREF_TYPE_IMMINENT,
DREF_TYPE_LOAN,
type DrefStatus,
Expand Down Expand Up @@ -167,7 +167,7 @@ function DrefTableActions(props: Props) {
pending: publishDrefPending,
} = useLazyRequest({
method: 'POST',
url: '/api/v2/dref/{id}/publish/',
url: '/api/v2/dref/{id}/approve/',
pathVariables: { id: String(id) },
// FIXME: typings should be fixed in the server
body: () => ({} as never),
Expand Down Expand Up @@ -198,7 +198,7 @@ function DrefTableActions(props: Props) {
pending: publishOpsUpdatePending,
} = useLazyRequest({
method: 'POST',
url: '/api/v2/dref-op-update/{id}/publish/',
url: '/api/v2/dref-op-update/{id}/approve/',
pathVariables: { id: String(id) },
// FIXME: typings should be fixed in the server
body: () => ({} as never),
Expand Down Expand Up @@ -229,7 +229,7 @@ function DrefTableActions(props: Props) {
pending: publishFinalReportPending,
} = useLazyRequest({
method: 'POST',
url: '/api/v2/dref-final-report/{id}/publish/',
url: '/api/v2/dref-final-report/{id}/approve/',
pathVariables: { id: String(id) },
// FIXME: typings should be fixed in the server
body: () => ({} as never),
Expand Down Expand Up @@ -385,7 +385,7 @@ function DrefTableActions(props: Props) {

const canDownloadAllocation = (applicationType === 'DREF' || applicationType === 'OPS_UPDATE');

const canApprove = status === DREF_STATUS_IN_PROGRESS && hasPermissionToApprove;
const canApprove = status === DREF_STATUS_DRAFT && hasPermissionToApprove;

const shouldConfirmImminentAddOpsUpdate = drefType === DREF_TYPE_IMMINENT && isDrefImminentV2;

Expand Down Expand Up @@ -494,7 +494,7 @@ function DrefTableActions(props: Props) {
</>
)}
>
{status === DREF_STATUS_IN_PROGRESS && applicationType === 'DREF' && (
{status === DREF_STATUS_DRAFT && applicationType === 'DREF' && (
<Link
to="drefApplicationForm"
urlParams={{ drefId: id }}
Expand All @@ -504,7 +504,7 @@ function DrefTableActions(props: Props) {
{strings.dropdownActionEditLabel}
</Link>
)}
{status === DREF_STATUS_IN_PROGRESS && applicationType === 'OPS_UPDATE' && (
{status === DREF_STATUS_DRAFT && applicationType === 'OPS_UPDATE' && (
<Link
to="drefOperationalUpdateForm"
urlParams={{ opsUpdateId: id }}
Expand All @@ -514,7 +514,7 @@ function DrefTableActions(props: Props) {
{strings.dropdownActionEditLabel}
</Link>
)}
{status === DREF_STATUS_IN_PROGRESS && applicationType === 'FINAL_REPORT' && (
{status === DREF_STATUS_DRAFT && applicationType === 'FINAL_REPORT' && (
<Link
to={isDrefImminentV2 ? 'drefFinalReportForm' : 'oldDrefFinalReportForm'}
urlParams={{ finalReportId: id }}
Expand Down
16 changes: 9 additions & 7 deletions app/src/views/DrefApplicationForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import DrefExportModal from '#components/domain/DrefExportModal';
import { type FieldReportItem as FieldReportSearchItem } from '#components/domain/FieldReportSearchSelectInput';
import FormFailedToLoadMessage from '#components/domain/FormFailedToLoadMessage';
import LanguageMismatchMessage from '#components/domain/LanguageMismatchMessage';
import NonEnglishFormCreationMessage from '#components/domain/NonEnglishFormCreationMessage';
import Link from '#components/Link';
import NonFieldError from '#components/NonFieldError';
import Page from '#components/Page';
Expand Down Expand Up @@ -383,6 +382,7 @@ export function Component() {
method: 'PATCH',
pathVariables: isDefined(drefId) ? { id: drefId } : undefined,
body: (formFields: DrefRequestBody) => formFields,
useCurrentLanguageForMutation: true,
onSuccess: (response) => {
alert.show(
strings.formSaveRequestSuccessMessage,
Expand Down Expand Up @@ -479,6 +479,7 @@ export function Component() {
url: '/api/v2/dref/',
method: 'POST',
body: (formFields: DrefRequestPostBody) => formFields,
useCurrentLanguageForMutation: true,
onSuccess: (response) => {
alert.show(
strings.formSaveRequestSuccessMessage,
Expand Down Expand Up @@ -609,13 +610,14 @@ export function Component() {
const disabled = fetchingDref || saveDrefPending;

// New DREFs can only be created in English
const nonEnglishCreate = isNotDefined(drefId) && currentLanguage !== 'en';
// const nonEnglishCreate = isNotDefined(drefId) && currentLanguage !== 'en';

const languageMismatch = isDefined(drefId)
&& isDefined(drefResponse)
&& currentLanguage !== drefResponse?.translation_module_original_language;
const shouldHideForm = nonEnglishCreate
|| languageMismatch
|| fetchingDref

const shouldHideForm = fetchingDref
// || nonEnglishCreate
|| isDefined(drefResponseError);

return (
Expand Down Expand Up @@ -730,11 +732,11 @@ export function Component() {
originalLanguage={drefResponse.translation_module_original_language}
/>
)}
{nonEnglishCreate && (
{/* nonEnglishCreate && (
<NonEnglishFormCreationMessage
title={strings.formNotAvailableInNonEnglishMessage}
/>
)}
) */}
{isDefined(drefResponseError) && (
<FormFailedToLoadMessage
title={strings.formLoadErrorTitle}
Expand Down
5 changes: 3 additions & 2 deletions app/src/views/DrefFinalReportForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export function Component() {
method: 'PATCH',
pathVariables: isDefined(finalReportId) ? { id: finalReportId } : undefined,
body: (formFields: FinalReportRequestBody) => formFields,
useCurrentLanguageForMutation: true,
onSuccess: (response) => {
alert.show(
strings.formSaveRequestSuccessMessage,
Expand Down Expand Up @@ -409,8 +410,8 @@ export function Component() {
const languageMismatch = isDefined(finalReportId)
&& isDefined(finalReportResponse)
&& currentLanguage !== finalReportResponse?.translation_module_original_language;
const shouldHideForm = languageMismatch
|| fetchingFinalReport

const shouldHideForm = fetchingFinalReport
|| isDefined(finalReportResponseError);

return (
Expand Down
8 changes: 5 additions & 3 deletions app/src/views/DrefOperationalUpdateForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import NonFieldError from '#components/NonFieldError';
import Page from '#components/Page';
import useCurrentLanguage from '#hooks/domain/useCurrentLanguage';
import useAlert from '#hooks/useAlert';
import { DREF_STATUS_APPROVED } from '#utils/constants';
import {
type GoApiResponse,
useLazyRequest,
Expand Down Expand Up @@ -313,7 +314,7 @@ export function Component() {
const prevOperationalUpdateId = useMemo(() => {
const currentOpsUpdate = drefResponse
?.operational_update_details
?.find((ou) => !ou.is_published);
?.find((ou) => !(ou.status === DREF_STATUS_APPROVED));

if (isNotDefined(currentOpsUpdate)) {
return undefined;
Expand Down Expand Up @@ -344,6 +345,7 @@ export function Component() {
} = useLazyRequest({
url: '/api/v2/dref-op-update/{id}/',
method: 'PATCH',
useCurrentLanguageForMutation: true,
pathVariables: isDefined(opsUpdateId) ? { id: opsUpdateId } : undefined,
body: (formFields: OpsUpdateRequestBody) => formFields,
onSuccess: (response) => {
Expand Down Expand Up @@ -575,8 +577,8 @@ export function Component() {
const languageMismatch = isDefined(opsUpdateId)
&& isDefined(drefResponse)
&& currentLanguage !== opsUpdateResponse?.translation_module_original_language;
const shouldHideForm = languageMismatch
|| fetchingOpsUpdate

const shouldHideForm = fetchingOpsUpdate
|| isDefined(opsUpdateResponseError);

return (
Expand Down
Loading