Skip to content

Commit

Permalink
tenant configuration uplaoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mithunhegde-egov committed Sep 20, 2024
1 parent d01455a commit 281fb5a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ApiCacheService } from "../../atoms/ApiCacheService";
import { TenantConfigSearch } from "../../elements/TenantConfigService";

const getImgUrl = (url, fallbackUrl) => {

if (!url && fallbackUrl) {
return fallbackUrl;
}
Expand Down Expand Up @@ -65,35 +66,46 @@ export const StoreService = {
const fetchTenantConfig = async () => {
const tenantConfigs = await TenantConfigSearch.tenant(stateCode);
const tenantConfigSearch = tenantConfigs?.tenantConfigs ? tenantConfigs?.tenantConfigs : null;
const logoArray = tenantConfigSearch[0].documents
.filter(doc => doc.type === "logoUrl")
.map(doc => doc.fileStoreId);

const bannerArray = tenantConfigSearch[0].documents
.filter(doc => doc.type === "bannerUrl")
.map(doc => doc.fileStoreId);

const logoUrl = await Digit.UploadServices.Filefetch(logoArray, tenantConfigSearch?.[0]?.code);
const bannerUrl = await Digit.UploadServices.Filefetch(bannerArray, tenantConfigSearch?.[0]?.code);

return {
languages: stateInfo.hasLocalisation ? stateInfo.languages : [{ label: "ENGLISH", value: Digit.Utils.getDefaultLanguage() }],
stateInfo: {
code: tenantConfigFetch ? tenantConfigSearch?.[0]?.code : stateInfo.code,
name: tenantConfigFetch ? tenantConfigSearch?.[0]?.name : stateInfo.name,
logoUrl: tenantConfigFetch ? tenantConfigSearch?.[0]?.documents?.find((item) => item.type === "logoUrl")?.url : stateInfo.logoUrl,
logoUrl: tenantConfigFetch ? logoUrl ? logoUrl : tenantConfigSearch?.[0]?.documents?.find((item) => item.type === "logoUrl")?.url : stateInfo.logoUrl,
statelogo: tenantConfigFetch ? tenantConfigSearch?.[0]?.documents?.find((item) => item.type === "statelogo")?.url : stateInfo.statelogo,
logoUrlWhite: tenantConfigFetch
? tenantConfigSearch?.[0]?.documents?.find((item) => item.type === "logoUrlWhite")?.url
: stateInfo.logoUrlWhite,
bannerUrl: tenantConfigFetch ? tenantConfigSearch?.[0]?.documents?.find((item) => item.type === "bannerUrl")?.url : stateInfo.bannerUrl,
bannerUrl: tenantConfigFetch ? bannerUrl ? bannerUrl : tenantConfigSearch?.[0]?.documents?.find((item) => item.type === "bannerUrl")?.url : stateInfo.bannerUrl,
},
localizationModules: stateInfo.localizationModules,
modules: MdmsRes?.tenant?.citymodule?.filter((module) => module?.active)?.filter((module) => enabledModules?.includes(module?.code))?.sort((x,y)=>x?.order-y?.order)|| [],
modules: MdmsRes?.tenant?.citymodule?.filter((module) => module?.active)?.filter((module) => enabledModules?.includes(module?.code))?.sort((x, y) => x?.order - y?.order) || [],
uiHomePage: uiHomePage
};
};
const initData = tenantConfigFetch ? await fetchTenantConfig() : {
languages: stateInfo.hasLocalisation ? stateInfo.languages : [{ label: "ENGLISH", value: Digit.Utils.getDefaultLanguage() }],
stateInfo: {
code: stateInfo.code,
name: stateInfo.name,
name: stateInfo.name,
logoUrl: stateInfo.logoUrl,
statelogo: stateInfo.statelogo,
logoUrlWhite: stateInfo.logoUrlWhite,
bannerUrl: stateInfo.bannerUrl,
},
localizationModules: stateInfo.localizationModules,
modules: MdmsRes?.tenant?.citymodule?.filter((module) => module?.active)?.filter((module) => enabledModules?.includes(module?.code))?.sort((x,y)=>x?.order-y?.order)|| [],
modules: MdmsRes?.tenant?.citymodule?.filter((module) => module?.active)?.filter((module) => enabledModules?.includes(module?.code))?.sort((x, y) => x?.order - y?.order) || [],
uiHomePage: uiHomePage
};
initData.selectedLanguage = Digit.SessionStorage.get("locale") || initData.languages[0].value;
Expand All @@ -105,9 +117,9 @@ export const StoreService = {
.flat()
.reduce((unique, ele) => (unique.find((item) => item.code === ele.code) ? unique : [...unique, ele]), []);
initData.tenants = MdmsRes?.tenant?.tenants
.map((tenant) => ({ i18nKey: `TENANT_TENANTS_${tenant.code.replace(".", "_").toUpperCase()}`, ...tenant }));
// .filter((item) => !!moduleTenants.find((mt) => mt.code === item.code))
// .map((tenant) => ({ i18nKey: `TENANT_TENANTS_${tenant.code.replace(".", "_").toUpperCase()}`, ...tenant }));
.map((tenant) => ({ i18nKey: `TENANT_TENANTS_${tenant.code.replace(".", "_").toUpperCase()}`, ...tenant }));
// .filter((item) => !!moduleTenants.find((mt) => mt.code === item.code))
// .map((tenant) => ({ i18nKey: `TENANT_TENANTS_${tenant.code.replace(".", "_").toUpperCase()}`, ...tenant }));

await LocalizationService.getLocale({
modules: [
Expand All @@ -128,7 +140,7 @@ export const StoreService = {
},
defaultData: async (stateCode, moduleCode, language, modulePrefix) => {
let moduleCodes = [];
if(typeof moduleCode !== "string") moduleCode.forEach(code => { moduleCodes.push(modulePrefix ? `${modulePrefix}-${code.toLowerCase()}` : `${code.toLowerCase()}`) });
if (typeof moduleCode !== "string") moduleCode.forEach(code => { moduleCodes.push(modulePrefix ? `${modulePrefix}-${code.toLowerCase()}` : `${code.toLowerCase()}`) });
const LocalePromise = LocalizationService.getLocale({
modules: typeof moduleCode == "string" ? modulePrefix ? [`${modulePrefix}-${moduleCode.toLowerCase()}`] : [`${moduleCode.toLowerCase()}`] : moduleCodes,
locale: language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ const ConfigUploaderComponent = ({ onSelect, ...props }) => {
// }
/>
</LabelFieldPair>
{showToast && (
<Toast
error={isError}
label={toastMessage}
onClose={() => setShowToast(false)}
/>
)}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ const LogoUploaderComponent = ({ onSelect, ...props }) => {
// }
/>
</LabelFieldPair>
{showToast && (
<Toast
error={isError}
label={toastMessage}
onClose={() => setShowToast(false)}
/>
)}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const TenantConfigUpload = () => {
const tenantId = Digit.ULBService.getCurrentTenantId();
const { t } = useTranslation();
const history = useHistory();
const [showToast, setShowToast] = useState(false);
const [showToast, setShowToast] = useState(null);
const [toastMessage, setToastMessage] = useState("");
const [isError, setIsError] = useState(false);
const [uploadData, setUploadData] = useState([]); // State to store the uploaded data
Expand Down Expand Up @@ -160,7 +160,7 @@ const TenantConfigUpload = () => {
label={t("SANDBOX_CONFIG_UPLOAD_DONE")}
config={config}
defaultValues={defaultValue}
onFormValueChange={(setValue, formData, formState, reset, setError, clearErrors, trigger, getValues) => {}}
onFormValueChange={(setValue, formData, formState, reset, setError, clearErrors, trigger, getValues) => { }}
onSubmit={(data) => onSubmit(data)}
fieldStyle={fieldStyle}
noBreakLine={true}
Expand Down

0 comments on commit 281fb5a

Please sign in to comment.