@visns-studio/visns-components 5.15.13 → 5.15.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
95
95
|
},
|
|
96
96
|
"name": "@visns-studio/visns-components",
|
|
97
|
-
"version": "5.15.
|
|
97
|
+
"version": "5.15.14",
|
|
98
98
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
99
99
|
"main": "src/index.js",
|
|
100
100
|
"files": [
|
|
@@ -117,6 +117,8 @@ import {
|
|
|
117
117
|
renderStageCounterColumn,
|
|
118
118
|
renderGalleryColumn,
|
|
119
119
|
renderTotalColumn,
|
|
120
|
+
renderPhoneColumn,
|
|
121
|
+
renderAbnColumn,
|
|
120
122
|
} from './columns/ColumnRenderers.jsx';
|
|
121
123
|
import _ from 'lodash';
|
|
122
124
|
|
|
@@ -2921,6 +2923,16 @@ const DataGrid = forwardRef(
|
|
|
2921
2923
|
column,
|
|
2922
2924
|
commonProps,
|
|
2923
2925
|
});
|
|
2926
|
+
case 'phone':
|
|
2927
|
+
return renderPhoneColumn({
|
|
2928
|
+
column,
|
|
2929
|
+
commonProps,
|
|
2930
|
+
});
|
|
2931
|
+
case 'abn':
|
|
2932
|
+
return renderAbnColumn({
|
|
2933
|
+
column,
|
|
2934
|
+
commonProps,
|
|
2935
|
+
});
|
|
2924
2936
|
default:
|
|
2925
2937
|
columnId = Array.isArray(column.id)
|
|
2926
2938
|
? column.id.join('-')
|
|
@@ -2486,3 +2486,105 @@ export const renderTotalColumn = () => {
|
|
|
2486
2486
|
},
|
|
2487
2487
|
};
|
|
2488
2488
|
};
|
|
2489
|
+
|
|
2490
|
+
// Phone Number formatter
|
|
2491
|
+
const formatPhoneNumber = (phoneNumber) => {
|
|
2492
|
+
if (!phoneNumber) return '';
|
|
2493
|
+
|
|
2494
|
+
// Remove all non-digit characters
|
|
2495
|
+
const cleanNumber = phoneNumber.replace(/\D/g, '');
|
|
2496
|
+
|
|
2497
|
+
// Check if it's an Australian mobile number (starts with 04 and has 10 digits)
|
|
2498
|
+
if (cleanNumber.match(/^04\d{8}$/)) {
|
|
2499
|
+
// Mobile format: 0400 000 000
|
|
2500
|
+
return cleanNumber.replace(/(\d{4})(\d{3})(\d{3})/, '$1 $2 $3');
|
|
2501
|
+
}
|
|
2502
|
+
|
|
2503
|
+
// Check if it's a 1300/1800 number (10 digits starting with 1300 or 1800)
|
|
2504
|
+
if (cleanNumber.match(/^1[38]00\d{6}$/)) {
|
|
2505
|
+
// 1300/1800 format: 1300 000 000
|
|
2506
|
+
return cleanNumber.replace(/(\d{4})(\d{3})(\d{3})/, '$1 $2 $3');
|
|
2507
|
+
}
|
|
2508
|
+
|
|
2509
|
+
// Check if it's an Australian landline number (8 digits with area code, or 10 digits total)
|
|
2510
|
+
if (cleanNumber.match(/^0[2-9]\d{8}$/)) {
|
|
2511
|
+
// Landline format: (02) 0000 0000
|
|
2512
|
+
return cleanNumber.replace(/(\d{2})(\d{4})(\d{4})/, '($1) $2 $3');
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
// If it doesn't match standard Australian patterns, return as is with some basic formatting
|
|
2516
|
+
if (cleanNumber.length >= 8) {
|
|
2517
|
+
// Generic formatting for longer numbers
|
|
2518
|
+
if (cleanNumber.length === 8) {
|
|
2519
|
+
return cleanNumber.replace(/(\d{4})(\d{4})/, '$1 $2');
|
|
2520
|
+
} else if (cleanNumber.length === 9) {
|
|
2521
|
+
return cleanNumber.replace(/(\d{1})(\d{4})(\d{4})/, '$1 $2 $3');
|
|
2522
|
+
} else if (cleanNumber.length === 10) {
|
|
2523
|
+
return cleanNumber.replace(/(\d{2})(\d{4})(\d{4})/, '($1) $2 $3');
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
// Return original if no formatting pattern matches
|
|
2528
|
+
return phoneNumber;
|
|
2529
|
+
};
|
|
2530
|
+
|
|
2531
|
+
// ABN formatter
|
|
2532
|
+
const formatABN = (abn) => {
|
|
2533
|
+
if (!abn) return '';
|
|
2534
|
+
|
|
2535
|
+
// Remove all non-digit characters
|
|
2536
|
+
const cleanABN = abn.replace(/\D/g, '');
|
|
2537
|
+
|
|
2538
|
+
// Check if it's a valid 11-digit ABN
|
|
2539
|
+
if (cleanABN.length === 11) {
|
|
2540
|
+
// Format as: 00 000 000 000
|
|
2541
|
+
return cleanABN.replace(/(\d{2})(\d{3})(\d{3})(\d{3})/, '$1 $2 $3 $4');
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
// Return original if not 11 digits
|
|
2545
|
+
return abn;
|
|
2546
|
+
};
|
|
2547
|
+
|
|
2548
|
+
// Phone Column Renderer
|
|
2549
|
+
export const renderPhoneColumn = ({ column, commonProps }) => {
|
|
2550
|
+
return {
|
|
2551
|
+
...commonProps,
|
|
2552
|
+
name: column.id,
|
|
2553
|
+
sortable: true,
|
|
2554
|
+
render: ({ data }) => {
|
|
2555
|
+
if (data && data[column.id]) {
|
|
2556
|
+
const formattedPhone = formatPhoneNumber(data[column.id]);
|
|
2557
|
+
|
|
2558
|
+
return (
|
|
2559
|
+
<CellWithTooltip value={data[column.id]} columnType="phone">
|
|
2560
|
+
<span>{formattedPhone}</span>
|
|
2561
|
+
</CellWithTooltip>
|
|
2562
|
+
);
|
|
2563
|
+
} else {
|
|
2564
|
+
return null;
|
|
2565
|
+
}
|
|
2566
|
+
},
|
|
2567
|
+
};
|
|
2568
|
+
};
|
|
2569
|
+
|
|
2570
|
+
// ABN Column Renderer
|
|
2571
|
+
export const renderAbnColumn = ({ column, commonProps }) => {
|
|
2572
|
+
return {
|
|
2573
|
+
...commonProps,
|
|
2574
|
+
name: column.id,
|
|
2575
|
+
sortable: true,
|
|
2576
|
+
render: ({ data }) => {
|
|
2577
|
+
if (data && data[column.id]) {
|
|
2578
|
+
const formattedABN = formatABN(data[column.id]);
|
|
2579
|
+
|
|
2580
|
+
return (
|
|
2581
|
+
<CellWithTooltip value={data[column.id]} columnType="abn">
|
|
2582
|
+
<span>{formattedABN}</span>
|
|
2583
|
+
</CellWithTooltip>
|
|
2584
|
+
);
|
|
2585
|
+
} else {
|
|
2586
|
+
return null;
|
|
2587
|
+
}
|
|
2588
|
+
},
|
|
2589
|
+
};
|
|
2590
|
+
};
|